Renamed App.id to App.packageName

This commit is contained in:
Peter Serwylo 2015-12-21 07:07:59 +11:00
parent 756df4d635
commit 5779736913
16 changed files with 63 additions and 63 deletions

View File

@ -171,7 +171,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
ApkListAdapter(Context context, App app) {
super(context, 0);
final List<Apk> apks = ApkProvider.Helper.findByApp(context, app.id);
final List<Apk> apks = ApkProvider.Helper.findByApp(context, app.packageName);
for (final Apk apk : apks) {
if (apk.compatible || Preferences.get().showIncompatibleVersions()) {
add(apk);
@ -192,9 +192,9 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
// Installed the same version, but from someplace else.
final String installerPkgName;
try {
installerPkgName = mPm.getInstallerPackageName(app.id);
installerPkgName = mPm.getInstallerPackageName(app.packageName);
} catch (IllegalArgumentException e) {
Log.w(TAG, "Application " + app.id + " is not installed anymore");
Log.w(TAG, "Application " + app.packageName + " is not installed anymore");
return getString(R.string.app_not_installed);
}
if (TextUtils.isEmpty(installerPkgName)) {
@ -431,13 +431,13 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
localBroadcastManager = LocalBroadcastManager.getInstance(this);
// Check if a download is running for this app
if (AsyncDownloaderFromAndroid.isDownloading(this, app.id) >= 0) {
if (AsyncDownloaderFromAndroid.isDownloading(this, app.packageName) >= 0) {
// call install() to re-setup the listeners and downloaders
// the AsyncDownloader will not restart the download since the download is running,
// and thus the version we pass to install() is not important
refreshHeader();
refreshApkList();
final Apk apkToInstall = ApkProvider.Helper.find(this, app.id, app.suggestedVercode);
final Apk apkToInstall = ApkProvider.Helper.find(this, app.packageName, app.suggestedVercode);
install(apkToInstall);
}
@ -449,7 +449,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
// register observer to know when install status changes
myAppObserver = new AppObserver(new Handler());
getContentResolver().registerContentObserver(
AppProvider.getContentUri(app.id),
AppProvider.getContentUri(app.packageName),
true,
myAppObserver);
}
@ -510,7 +510,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
if (app != null && (app.ignoreAllUpdates != startingIgnoreAll
|| app.ignoreThisUpdate != startingIgnoreThis)) {
Utils.debugLog(TAG, "Updating 'ignore updates', as it has changed since we started the activity...");
setIgnoreUpdates(app.id, app.ignoreAllUpdates, app.ignoreThisUpdate);
setIgnoreUpdates(app.packageName, app.ignoreAllUpdates, app.ignoreThisUpdate);
}
localBroadcastManager.unregisterReceiver(downloaderProgressReceiver);
@ -531,7 +531,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
};
private void onAppChanged() {
if (!reset(app.id)) {
if (!reset(app.packageName)) {
AppDetails.this.finish();
return;
}
@ -622,7 +622,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
if (app == null)
return true;
if (mPm.getLaunchIntentForPackage(app.id) != null && app.canAndWantToUpdate()) {
if (mPm.getLaunchIntentForPackage(app.packageName) != null && app.canAndWantToUpdate()) {
MenuItemCompat.setShowAsAction(menu.add(
Menu.NONE, LAUNCH, 1, R.string.menu_launch)
.setIcon(R.drawable.ic_play_arrow_white),
@ -749,7 +749,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
return true;
case LAUNCH:
launchApk(app.id);
launchApk(app.packageName);
return true;
case SHARE:
@ -759,13 +759,13 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
case INSTALL:
// Note that this handles updating as well as installing.
if (app.suggestedVercode > 0) {
final Apk apkToInstall = ApkProvider.Helper.find(this, app.id, app.suggestedVercode);
final Apk apkToInstall = ApkProvider.Helper.find(this, app.packageName, app.suggestedVercode);
install(apkToInstall);
}
return true;
case UNINSTALL:
removeApk(app.id);
removeApk(app.packageName);
return true;
case IGNOREALL:
@ -880,7 +880,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
private void installApk(File file) {
try {
installer.installPackage(file, app.id);
installer.installPackage(file, app.packageName);
} catch (AndroidNotCompatibleException e) {
Log.e(TAG, "Android not compatible with this Installer!", e);
}
@ -903,7 +903,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
@Override
public void run() {
if (operation == Installer.InstallerCallback.OPERATION_INSTALL) {
PackageManagerCompat.setInstaller(mPm, app.id);
PackageManagerCompat.setInstaller(mPm, app.packageName);
}
onAppChanged();
@ -962,7 +962,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, app.name);
shareIntent.putExtra(Intent.EXTRA_TEXT, app.name + " (" + app.summary + ") - https://f-droid.org/app/" + app.id);
shareIntent.putExtra(Intent.EXTRA_TEXT, app.name + " (" + app.summary + ") - https://f-droid.org/app/" + app.packageName);
startActivity(Intent.createChooser(shareIntent, getString(R.string.menu_share)));
}
@ -1016,7 +1016,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
switch (requestCode) {
case REQUEST_ENABLE_BLUETOOTH:
fdroidApp.sendViaBluetooth(this, resultCode, app.id);
fdroidApp.sendViaBluetooth(this, resultCode, app.packageName);
break;
}
}
@ -1210,7 +1210,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
// App ID
final TextView appIdView = (TextView) view.findViewById(R.id.appid);
if (prefs.expertMode())
appIdView.setText(app.id);
appIdView.setText(app.packageName);
else
appIdView.setVisibility(View.GONE);
@ -1567,13 +1567,13 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
} else if (app.isInstalled()) {
installed = true;
statusView.setText(getString(R.string.details_installed, app.installedVersionName));
NfcHelper.setAndroidBeam(activity, app.id);
NfcHelper.setAndroidBeam(activity, app.packageName);
if (app.canAndWantToUpdate()) {
updateWanted = true;
btMain.setText(R.string.menu_upgrade);
} else {
updateWanted = false;
if (activity.mPm.getLaunchIntentForPackage(app.id) != null) {
if (activity.mPm.getLaunchIntentForPackage(app.packageName) != null) {
btMain.setText(R.string.menu_launch);
} else {
btMain.setText(R.string.menu_uninstall);
@ -1601,7 +1601,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
AppDetails activity = (AppDetails) getActivity();
if (updateWanted) {
if (app.suggestedVercode > 0) {
final Apk apkToInstall = ApkProvider.Helper.find(activity, app.id, app.suggestedVercode);
final Apk apkToInstall = ApkProvider.Helper.find(activity, app.packageName, app.suggestedVercode);
activity.install(apkToInstall);
return;
}
@ -1609,16 +1609,16 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
// If installed
if (installed) {
// If "launchable", launch
if (activity.mPm.getLaunchIntentForPackage(app.id) != null) {
activity.launchApk(app.id);
if (activity.mPm.getLaunchIntentForPackage(app.packageName) != null) {
activity.launchApk(app.packageName);
} else {
activity.removeApk(app.id);
activity.removeApk(app.packageName);
}
// If not installed, install
} else if (app.suggestedVercode > 0) {
btMain.setEnabled(false);
btMain.setText(R.string.system_install_installing);
final Apk apkToInstall = ApkProvider.Helper.find(activity, app.id, app.suggestedVercode);
final Apk apkToInstall = ApkProvider.Helper.find(activity, app.packageName, app.suggestedVercode);
activity.install(apkToInstall);
}
}
@ -1647,7 +1647,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
}
protected void remove() {
installListener.removeApk(getApp().id);
installListener.removeApk(getApp().packageName);
}
protected App getApp() {

View File

@ -222,7 +222,7 @@ public class RepoXMLHandler extends DefaultHandler {
receiver.receiveApp(curapp, apksList);
curapp = null;
apksList = new ArrayList<>();
// If the app id is already present in this apps list, then it
// If the app packageName is already present in this apps list, then it
// means the same index file has a duplicate app, which should
// not be allowed.
// However, I'm thinking that it should be undefined behaviour,
@ -249,10 +249,10 @@ public class RepoXMLHandler extends DefaultHandler {
repoDescription = cleanWhiteSpace(attributes.getValue("", "description"));
} else if ("application".equals(localName) && curapp == null) {
curapp = new App();
curapp.id = attributes.getValue("", "id");
curapp.packageName = attributes.getValue("", "id");
} else if ("package".equals(localName) && curapp != null && curapk == null) {
curapk = new Apk();
curapk.id = curapp.id;
curapk.id = curapp.packageName;
curapk.repo = repo.getId();
currentApkHashType = null;

View File

@ -22,7 +22,7 @@ public class ApkProvider extends FDroidProvider {
/**
* SQLite has a maximum of 999 parameters in a query. Each apk we add
* requires two (id and vercode) so we can only query half of that. Then,
* requires two (packageName and vercode) so we can only query half of that. Then,
* we may want to add additional constraints, so we give our self some
* room by saying only 450 apks can be queried at once.
*/
@ -62,7 +62,7 @@ public class ApkProvider extends FDroidProvider {
public static void deleteApksByApp(Context context, App app) {
ContentResolver resolver = context.getContentResolver();
final Uri uri = getAppUri(app.id);
final Uri uri = getAppUri(app.packageName);
resolver.delete(uri, null, null);
}
@ -135,7 +135,7 @@ public class ApkProvider extends FDroidProvider {
}
/**
* Returns apks in the database, which have the same id and version as
* Returns apks in the database, which have the same packageName and version as
* one of the apks in the "apks" argument.
*/
public static List<Apk> knownApks(Context context, List<Apk> apks, String[] fields) {
@ -340,7 +340,7 @@ public class ApkProvider extends FDroidProvider {
if (i != 0) {
builder.append(',');
}
builder.append(apks.get(i).id);
builder.append(apks.get(i).packageName);
}
return builder.toString();
}

View File

@ -31,7 +31,7 @@ public class App extends ValueObject implements Comparable<App> {
// True if compatible with the device (i.e. if at least one apk is)
public boolean compatible;
public String id = "unknown";
public String packageName = "unknown";
public String name = "Unknown";
public String summary = "Unknown application";
public String icon;
@ -125,7 +125,7 @@ public class App extends ValueObject implements Comparable<App> {
compatible = cursor.getInt(i) == 1;
break;
case AppProvider.DataColumns.PACKAGE_NAME:
id = cursor.getString(i);
packageName = cursor.getString(i);
break;
case AppProvider.DataColumns.NAME:
name = cursor.getString(i);
@ -252,7 +252,7 @@ public class App extends ValueObject implements Comparable<App> {
this.summary = "(installed by " + installerPackageLabel + ")";
else
this.summary = (String) appDescription.subSequence(0, 40);
this.id = appInfo.packageName;
this.packageName = appInfo.packageName;
this.added = new Date(packageInfo.firstInstallTime);
this.lastUpdated = new Date(packageInfo.lastUpdateTime);
this.description = "<p>";
@ -273,7 +273,7 @@ public class App extends ValueObject implements Comparable<App> {
apk.added = this.added;
apk.minSdkVersion = Utils.getMinSdkVersion(context, packageName);
apk.maxSdkVersion = Utils.getMaxSdkVersion(context, packageName);
apk.id = this.id;
apk.id = this.packageName;
apk.installedFile = apkFile;
apk.permissions = Utils.CommaSeparatedList.make(packageInfo.requestedPermissions);
apk.apkName = apk.id + "_" + apk.vercode + ".apk";
@ -352,7 +352,7 @@ public class App extends ValueObject implements Comparable<App> {
public boolean isValid() {
if (TextUtils.isEmpty(this.name)
|| TextUtils.isEmpty(this.id))
|| TextUtils.isEmpty(this.packageName))
return false;
if (this.installedApk == null)
@ -369,7 +369,7 @@ public class App extends ValueObject implements Comparable<App> {
public ContentValues toContentValues() {
final ContentValues values = new ContentValues();
values.put(AppProvider.DataColumns.PACKAGE_NAME, id);
values.put(AppProvider.DataColumns.PACKAGE_NAME, packageName);
values.put(AppProvider.DataColumns.NAME, name);
values.put(AppProvider.DataColumns.SUMMARY, summary);
values.put(AppProvider.DataColumns.ICON, icon);

View File

@ -523,7 +523,7 @@ public class AppProvider extends FDroidProvider {
if (i != 0) {
builder.append(',');
}
builder.append(apps.get(i).id);
builder.append(apps.get(i).packageName);
}
return getContentUri().buildUpon()
.appendPath(PATH_APPS)
@ -532,7 +532,7 @@ public class AppProvider extends FDroidProvider {
}
public static Uri getContentUri(App app) {
return getContentUri(app.id);
return getContentUri(app.packageName);
}
public static Uri getContentUri(String appId) {

View File

@ -109,7 +109,7 @@ public class InstalledAppProvider extends FDroidProvider {
} catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
Utils.debugLog(TAG, "Could not get application label", e);
}
return packageName; // all else fails, return id
return packageName; // all else fails, return packageName
}
public static String getPackageSig(PackageInfo info) {

View File

@ -73,7 +73,7 @@ public class RepoPersister {
public void saveToDb(App app, List<Apk> packages) throws RepoUpdater.UpdateException {
appsToSave.add(app);
apksToSave.put(app.id, packages);
apksToSave.put(app.packageName, packages);
if (appsToSave.size() >= MAX_APP_BUFFER) {
flushBufferToDb();
@ -217,7 +217,7 @@ public class RepoPersister {
*/
private boolean isAppInDatabase(App app) {
String[] fields = {AppProvider.DataColumns.PACKAGE_NAME};
App found = AppProvider.Helper.findById(context.getContentResolver(), app.id, fields);
App found = AppProvider.Helper.findById(context.getContentResolver(), app.packageName, fields);
return found != null;
}

View File

@ -48,7 +48,7 @@ public class TempAppProvider extends AppProvider {
}
public static Uri getAppUri(App app) {
return Uri.withAppendedPath(getContentUri(), app.id);
return Uri.withAppendedPath(getContentUri(), app.packageName);
}
public static class Helper {

View File

@ -282,8 +282,8 @@ public final class LocalRepoManager {
for (final App app : apps.values()) {
if (app.installedApk != null) {
try {
appInfo = pm.getApplicationInfo(app.id, PackageManager.GET_META_DATA);
copyIconToRepo(appInfo.loadIcon(pm), app.id, app.installedApk.vercode);
appInfo = pm.getApplicationInfo(app.packageName, PackageManager.GET_META_DATA);
copyIconToRepo(appInfo.loadIcon(pm), app.packageName, app.installedApk.vercode);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Error getting app icon", e);
}
@ -413,9 +413,9 @@ public final class LocalRepoManager {
private void tagApplication(App app) throws IOException {
serializer.startTag("", "application");
serializer.attribute("", "id", app.id);
serializer.attribute("", "id", app.packageName);
tag("id", app.id);
tag("id", app.packageName);
tag("added", app.added);
tag("lastupdated", app.lastUpdated);
tag("name", app.name);

View File

@ -156,7 +156,7 @@ public abstract class AppListFragment extends ListFragment implements
if (cursor != null) {
final App app = new App(cursor);
Intent intent = getAppDetailsIntent();
intent.putExtra(AppDetails.EXTRA_APPID, app.id);
intent.putExtra(AppDetails.EXTRA_APPID, app.packageName);
intent.putExtra(AppDetails.EXTRA_FROM, getFromTitle());
startActivityForResult(intent, REQUEST_APPDETAILS);
}

View File

@ -110,7 +110,7 @@ public class SearchResultsFragment extends ListFragment implements LoaderManager
final App app = new App((Cursor) adapter.getItem(position));
Intent intent = new Intent(getActivity(), AppDetails.class);
intent.putExtra(AppDetails.EXTRA_APPID, app.id);
intent.putExtra(AppDetails.EXTRA_APPID, app.packageName);
intent.putExtra(AppDetails.EXTRA_HINT_SEARCHING, true);
startActivityForResult(intent, REQUEST_APPDETAILS);
super.onListItemClick(l, v, position, id);

View File

@ -125,7 +125,7 @@ public class SwapAppsView extends ListView implements
private void pollForUpdates() {
if (adapter.getCount() > 1 ||
(adapter.getCount() == 1 && !new App((Cursor) adapter.getItem(0)).id.equals("org.fdroid.fdroid"))) {
(adapter.getCount() == 1 && !new App((Cursor) adapter.getItem(0)).packageName.equals("org.fdroid.fdroid"))) {
Utils.debugLog(TAG, "Not polling for new apps from swap repo, because we already have more than one.");
return;
}
@ -333,7 +333,7 @@ public class SwapAppsView extends ListView implements
public void onChange(boolean selfChange) {
Activity activity = getActivity();
if (activity != null) {
app = AppProvider.Helper.findById(getActivity().getContentResolver(), app.id);
app = AppProvider.Helper.findById(getActivity().getContentResolver(), app.packageName);
apkToInstall = null; // Force lazy loading to fetch correct apk next time.
resetView();
}
@ -350,7 +350,7 @@ public class SwapAppsView extends ListView implements
}
public void setApp(@NonNull App app) {
if (this.app == null || !this.app.id.equals(app.id)) {
if (this.app == null || !this.app.packageName.equals(app.packageName)) {
this.app = app;
apkToInstall = null; // Force lazy loading to fetch the correct apk next time.
@ -361,7 +361,7 @@ public class SwapAppsView extends ListView implements
// implemented on API-16, so leaving like this for now.
getActivity().getContentResolver().unregisterContentObserver(appObserver);
getActivity().getContentResolver().registerContentObserver(
AppProvider.getContentUri(this.app.id), true, appObserver);
AppProvider.getContentUri(this.app.packageName), true, appObserver);
}
resetView();
}
@ -372,7 +372,7 @@ public class SwapAppsView extends ListView implements
*/
private Apk getApkToInstall() {
if (apkToInstall == null) {
apkToInstall = ApkProvider.Helper.find(getActivity(), app.id, app.suggestedVercode);
apkToInstall = ApkProvider.Helper.find(getActivity(), app.packageName, app.suggestedVercode);
}
return apkToInstall;
}

View File

@ -781,14 +781,14 @@ public class SwapWorkflowActivity extends AppCompatActivity {
}
public void install(@NonNull final App app) {
final Apk apkToInstall = ApkProvider.Helper.find(this, app.id, app.suggestedVercode);
final Apk apkToInstall = ApkProvider.Helper.find(this, app.packageName, app.suggestedVercode);
final ApkDownloader downloader = new ApkDownloader(this, app, apkToInstall, apkToInstall.repoAddress);
downloader.setProgressListener(new ProgressListener() {
@Override
public void onProgress(Event event) {
switch (event.type) {
case ApkDownloader.EVENT_APK_DOWNLOAD_COMPLETE:
handleDownloadComplete(downloader.localFile(), app.id);
handleDownloadComplete(downloader.localFile(), app.packageName);
break;
case ApkDownloader.EVENT_ERROR:
break;

View File

@ -93,7 +93,7 @@ public class AppProviderTest extends FDroidProviderTest<AppProvider> {
assertValidUri(AppProvider.getCanUpdateUri());
App app = new App();
app.id = "org.fdroid.fdroid";
app.packageName = "org.fdroid.fdroid";
List<App> apps = new ArrayList<>(1);
apps.add(app);
@ -178,7 +178,7 @@ public class AppProviderTest extends FDroidProviderTest<AppProvider> {
canUpdateCursor.moveToFirst();
List<String> canUpdateIds = new ArrayList<>(canUpdateCursor.getCount());
while (!canUpdateCursor.isAfterLast()) {
canUpdateIds.add(new App(canUpdateCursor).id);
canUpdateIds.add(new App(canUpdateCursor).packageName);
canUpdateCursor.moveToNext();
}
canUpdateCursor.close();
@ -230,7 +230,7 @@ public class AppProviderTest extends FDroidProviderTest<AppProvider> {
private void assertContainsOnlyIds(List<App> actualApps, String[] expectedIds) {
List<String> actualIds = new ArrayList<>(actualApps.size());
for (App app : actualApps) {
actualIds.add(app.id);
actualIds.add(app.packageName);
}
TestUtils.assertContainsOnly(actualIds, expectedIds);
}
@ -282,7 +282,7 @@ public class AppProviderTest extends FDroidProviderTest<AppProvider> {
cursor.moveToFirst();
App app = new App(cursor);
cursor.close();
assertEquals("org.fdroid.fdroid", app.id);
assertEquals("org.fdroid.fdroid", app.packageName);
assertEquals("F-Droid", app.name);
}

View File

@ -596,7 +596,7 @@ public class RepoXMLHandlerTest extends AndroidTestCase {
for (String id : expctedAppIds) {
boolean thisAppMissing = true;
for (App app : actualApps) {
if (TextUtils.equals(app.id, id)) {
if (TextUtils.equals(app.packageName, id)) {
thisAppMissing = false;
break;
}

View File

@ -9,7 +9,7 @@ public class MockApp extends App {
}
public MockApp(String id, String name) {
this.id = id;
this.packageName = id;
this.name = name;
}