Add internal implementation for notifyPackageUse

We have checks that prevent applications from modifying the usage
times of instant apps [and vice versa]. However, it's critical for
internal components such as the ActivityManager to be able to upate
this for all packages. Add an internal implementation of this
method that skips the checks.

Change-Id: Ib890296065024104cdaf7c8d64a5a7583d9062c1
Fixes: 65228752
Test: Manual. Run an application installed as an "instant app" and notice the usage time goes up
This commit is contained in:
Todd Kennedy
2017-08-31 16:10:29 -07:00
parent d9abde75e8
commit df113c36a7
3 changed files with 23 additions and 9 deletions

View File

@@ -378,4 +378,9 @@ public abstract class PackageManagerInternal {
* associated with an instant app. It may be kept after the instant app has been uninstalled.
*/
public abstract boolean hasInstantApplicationMetadata(String packageName, int userId);
/**
* Updates a package last used time.
*/
public abstract void notifyPackageUse(String packageName, int reason);
}

View File

@@ -3579,10 +3579,8 @@ public class ActivityManagerService extends IActivityManager.Stub
}
void notifyPackageUse(String packageName, int reason) {
IPackageManager pm = AppGlobals.getPackageManager();
try {
pm.notifyPackageUse(packageName, reason);
} catch (RemoteException e) {
synchronized(this) {
getPackageManagerInternalLocked().notifyPackageUse(packageName, reason);
}
}

View File

@@ -9844,14 +9844,18 @@ public class PackageManagerService extends IPackageManager.Stub
return;
}
}
final PackageParser.Package p = mPackages.get(packageName);
if (p == null) {
return;
}
p.mLastPackageUsageTimeInMills[reason] = System.currentTimeMillis();
notifyPackageUseLocked(packageName, reason);
}
}
private void notifyPackageUseLocked(String packageName, int reason) {
final PackageParser.Package p = mPackages.get(packageName);
if (p == null) {
return;
}
p.mLastPackageUsageTimeInMills[reason] = System.currentTimeMillis();
}
@Override
public void notifyDexLoad(String loadingPackageName, List<String> classLoaderNames,
List<String> classPaths, String loaderIsa) {
@@ -25502,6 +25506,13 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
return mInstantAppRegistry.hasInstantApplicationMetadataLPr(packageName, userId);
}
}
@Override
public void notifyPackageUse(String packageName, int reason) {
synchronized (mPackages) {
PackageManagerService.this.notifyPackageUseLocked(packageName, reason);
}
}
}
@Override