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

Commit 745766e1 authored by Robin Lee's avatar Robin Lee
Browse files

Merge commit 'bd107779' into HEAD

* commit 'bd107779':
  Forward package removed broadcast to KeyChainService

Test: make full -j30
Fix: 36568026
Change-Id: Icd3cda64e403212132e2c7d731e9793eb92c368a
parents df95d9c7 bd107779
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -22,10 +22,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Process;
import android.os.UserHandle;
import android.security.IKeyChainService;
import android.util.Slog;

import com.android.server.DeviceIdleController;
import com.android.server.LocalServices;
import com.android.server.SystemService;

/**
@@ -45,6 +48,11 @@ public class KeyChainSystemService extends SystemService {

    private static final String TAG = "KeyChainSystemService";

    /**
     * Maximum time limit for the KeyChain app to deal with packages being removed.
     */
    private static final int KEYCHAIN_IDLE_WHITELIST_DURATION_MS = 30 * 1000;

    public KeyChainSystemService(final Context context) {
        super(context);
    }
@@ -77,10 +85,25 @@ public class KeyChainSystemService extends SystemService {
                }
                intent.setComponent(service);
                intent.setAction(broadcastIntent.getAction());
                getContext().startServiceAsUser(intent, UserHandle.of(getSendingUserId()));
                startServiceInBackgroundAsUser(intent, UserHandle.of(getSendingUserId()));
            } catch (RuntimeException e) {
                Slog.e(TAG, "Unable to forward package removed broadcast to KeyChain", e);
            }
        }
    };


    private void startServiceInBackgroundAsUser(final Intent intent, final UserHandle user) {
        if (intent.getComponent() == null) {
            return;
        }

        final String packageName = intent.getComponent().getPackageName();
        final DeviceIdleController.LocalService idleController =
                LocalServices.getService(DeviceIdleController.LocalService.class);
        idleController.addPowerSaveTempWhitelistApp(Process.myUid(), packageName,
                KEYCHAIN_IDLE_WHITELIST_DURATION_MS, user.getIdentifier(), false, "keychain");

        getContext().startServiceAsUser(intent, user);
    }
}