Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7e45e36 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Re-run pinner service on camera app update and dex optimization." into oc-dev

parents 73c04555 f107a23f
Loading
Loading
Loading
Loading
+36 −6
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

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;
@@ -68,6 +71,19 @@ public final class PinnerService extends SystemService {

    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);
@@ -76,6 +92,11 @@ public final class PinnerService extends SystemService {
        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
@@ -85,6 +106,7 @@ public final class PinnerService extends SystemService {
        }
        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)
@@ -102,6 +124,17 @@ public final class PinnerService extends SystemService {
        mPinnerHandler.obtainMessage(PinnerHandler.PIN_CAMERA_MSG, userHandle, 0).sendToTarget();
    }

    /**
     * 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
     */
@@ -202,13 +235,10 @@ public final class PinnerService extends SystemService {
        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;
+13 −2
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import android.util.ArraySet;
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;
@@ -366,11 +368,20 @@ public class BackgroundDexOptService extends JobService {
            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