package com.android.server;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
private PinnerHandler mPinnerHandler = null;
+ private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ // If this user's camera app has been updated, update pinned files accordingly.
+ if (intent.getAction() == Intent.ACTION_PACKAGE_REPLACED) {
+ Uri packageUri = intent.getData();
+ ApplicationInfo cameraInfo = getCameraInfo(UserHandle.USER_SYSTEM);
+ if (cameraInfo.packageName == packageUri.getSchemeSpecificPart()) {
+ update();
+ }
+ }
+ }
+ };
public PinnerService(Context context) {
super(context);
mShouldPinCamera = context.getResources().getBoolean(
com.android.internal.R.bool.config_pinnerCameraApp);
mPinnerHandler = new PinnerHandler(BackgroundThread.get().getLooper());
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
+ filter.addDataScheme("package");
+ mContext.registerReceiver(mBroadcastReceiver, filter);
}
@Override
}
mBinderService = new BinderService();
publishBinderService("pinner", mBinderService);
+ publishLocalService(PinnerService.class, this);
mPinnerHandler.obtainMessage(PinnerHandler.PIN_ONSTART_MSG).sendToTarget();
mPinnerHandler.obtainMessage(PinnerHandler.PIN_CAMERA_MSG, UserHandle.USER_SYSTEM, 0)
}
/**
+ * Update the currently pinned files.
+ * Specifically, this only updates camera pinning.
+ * The other files pinned in onStart will not need to be updated.
+ */
+ public void update() {
+ Slog.i(TAG, "Updating pinned files.");
+ mPinnerHandler.obtainMessage(PinnerHandler.PIN_CAMERA_MSG, UserHandle.USER_SYSTEM, 0)
+ .sendToTarget();
+ }
+
+ /**
* Handler for on start pinning message
*/
private void handlePinOnStart() {
return cameraResolveInfo.activityInfo.applicationInfo;
}
+ /**
+ * If the camera app is already pinned, unpin and repin it.
+ */
private boolean pinCamera(int userHandle){
- //we may have already pinned a camera app. If we've pinned this
- //camera app, we're done. otherwise, unpin and pin the new app
- if (alreadyPinned(userHandle)){
- return true;
- }
-
ApplicationInfo cameraInfo = getCameraInfo(userHandle);
if (cameraInfo == null) {
return false;
import android.util.Log;
import com.android.server.pm.dex.DexManager;
+import com.android.server.LocalServices;
+import com.android.server.PinnerService;
import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;
return false;
}
+ boolean result;
if (params.getJobId() == JOB_POST_BOOT_UPDATE) {
- return runPostBootUpdate(params, pm, pkgs);
+ result = runPostBootUpdate(params, pm, pkgs);
} else {
- return runIdleOptimization(params, pm, pkgs);
+ result = runIdleOptimization(params, pm, pkgs);
}
+
+ PinnerService pinnerService = (PinnerService) LocalServices.getService(PinnerService.class);
+ if (pinnerService != null) {
+ Log.i(TAG, "Pinning optimized code");
+ pinnerService.update();
+ }
+
+ return result;
}
@Override