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

Commit 903d6414 authored by Ivan Podogov's avatar Ivan Podogov
Browse files

resolve merge conflicts of b1e2da7c to nyc-mr1-dev-plus-aosp

Test: build police
Change-Id: Ifec1ab6760ebb94b0b411c9c60f07066e151206b
parents eb0a34f2 b1e2da7c
Loading
Loading
Loading
Loading
+28 −4
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.app.ActivityThread;
import android.bluetooth.le.BluetoothLeAdvertiser;
import android.bluetooth.le.BluetoothLeAdvertiser;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanCallback;
@@ -254,6 +255,29 @@ public final class BluetoothAdapter {
    public static final String ACTION_REQUEST_ENABLE =
    public static final String ACTION_REQUEST_ENABLE =
            "android.bluetooth.adapter.action.REQUEST_ENABLE";
            "android.bluetooth.adapter.action.REQUEST_ENABLE";


    /**
     * Activity Action: Show a system activity that allows the user to turn off
     * Bluetooth. This is used only if permission review is enabled which is for
     * apps targeting API less than 23 require a permission review before any of
     * the app's components can run.
     * <p>This system activity will return once Bluetooth has completed turning
     * off, or the user has decided not to turn Bluetooth off.
     * <p>Notification of the result of this activity is posted using the
     * {@link android.app.Activity#onActivityResult} callback. The
     * <code>resultCode</code>
     * will be {@link android.app.Activity#RESULT_OK} if Bluetooth has been
     * turned off or {@link android.app.Activity#RESULT_CANCELED} if the user
     * has rejected the request or an error has occurred.
     * <p>Applications can also listen for {@link #ACTION_STATE_CHANGED}
     * for global notification whenever Bluetooth is turned on or off.
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
     *
     * @hide
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_REQUEST_DISABLE =
            "android.bluetooth.adapter.action.REQUEST_DISABLE";

    /**
    /**
     * Activity Action: Show a system activity that allows user to enable BLE scans even when
     * Activity Action: Show a system activity that allows user to enable BLE scans even when
     * Bluetooth is turned off.<p>
     * Bluetooth is turned off.<p>
@@ -768,7 +792,7 @@ public final class BluetoothAdapter {
                return true;
                return true;
            }
            }
            if (DBG) Log.d(TAG, "enableBLE(): Calling enable");
            if (DBG) Log.d(TAG, "enableBLE(): Calling enable");
            return mManagerService.enable();
            return mManagerService.enable(ActivityThread.currentPackageName());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
            Log.e(TAG, "", e);
        }
        }
@@ -895,7 +919,7 @@ public final class BluetoothAdapter {
            return true;
            return true;
        }
        }
        try {
        try {
            return mManagerService.enable();
            return mManagerService.enable(ActivityThread.currentPackageName());
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }
@@ -927,7 +951,7 @@ public final class BluetoothAdapter {
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    public boolean disable() {
    public boolean disable() {
        try {
        try {
            return mManagerService.disable(true);
            return mManagerService.disable(ActivityThread.currentPackageName(), true);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }
@@ -945,7 +969,7 @@ public final class BluetoothAdapter {
    public boolean disable(boolean persist) {
    public boolean disable(boolean persist) {


        try {
        try {
            return mManagerService.disable(persist);
            return mManagerService.disable(ActivityThread.currentPackageName(), persist);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -34,9 +34,9 @@ interface IBluetoothManager
    void registerStateChangeCallback(in IBluetoothStateChangeCallback callback);
    void registerStateChangeCallback(in IBluetoothStateChangeCallback callback);
    void unregisterStateChangeCallback(in IBluetoothStateChangeCallback callback);
    void unregisterStateChangeCallback(in IBluetoothStateChangeCallback callback);
    boolean isEnabled();
    boolean isEnabled();
    boolean enable();
    boolean enable(String packageName);
    boolean enableNoAutoConnect();
    boolean enableNoAutoConnect();
    boolean disable(boolean persist);
    boolean disable(String packageName, boolean persist);
    int getState();
    int getState();
    IBluetoothGatt getBluetoothGatt();
    IBluetoothGatt getBluetoothGatt();


+75 −15
Original line number Original line Diff line number Diff line
@@ -35,11 +35,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.database.ContentObserver;
import android.os.Binder;
import android.os.Binder;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Build;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Looper;
import android.os.Looper;
@@ -154,6 +156,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    private final Map <Integer, ProfileServiceConnections> mProfileServices =
    private final Map <Integer, ProfileServiceConnections> mProfileServices =
            new HashMap <Integer, ProfileServiceConnections>();
            new HashMap <Integer, ProfileServiceConnections>();


    private final boolean mPermissionReviewRequired;

    private void registerForAirplaneMode(IntentFilter filter) {
    private void registerForAirplaneMode(IntentFilter filter) {
        final ContentResolver resolver = mContext.getContentResolver();
        final ContentResolver resolver = mContext.getContentResolver();
        final String airplaneModeRadios = Settings.Global.getString(resolver,
        final String airplaneModeRadios = Settings.Global.getString(resolver,
@@ -183,7 +187,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            final boolean bluetoothDisallowed =
            final boolean bluetoothDisallowed =
                    newRestrictions.getBoolean(UserManager.DISALLOW_BLUETOOTH);
                    newRestrictions.getBoolean(UserManager.DISALLOW_BLUETOOTH);
            if ((mEnable || mEnableExternal) && bluetoothDisallowed) {
            if ((mEnable || mEnableExternal) && bluetoothDisallowed) {
                disable(true);
                try {
                  disable("android.os.UserManagerInternal", true);
                } catch (RemoteException e) {
                  // Shouldn't happen: startConsentUiIfNeeded not called
                  // when from system.
                }
            }
            }
        }
        }
    };
    };
@@ -257,6 +266,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        mHandler = new BluetoothHandler(IoThread.get().getLooper());
        mHandler = new BluetoothHandler(IoThread.get().getLooper());


        mContext = context;
        mContext = context;

        mPermissionReviewRequired = Build.PERMISSIONS_REVIEW_REQUIRED
                    || context.getResources().getBoolean(
                com.android.internal.R.bool.config_permissionReviewRequired);

        mBluetooth = null;
        mBluetooth = null;
        mBluetoothBinder = null;
        mBluetoothBinder = null;
        mBluetoothGatt = null;
        mBluetoothGatt = null;
@@ -669,7 +683,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        return true;
        return true;
    }
    }


    public boolean enable() {
    public boolean enable(String packageName) throws RemoteException {
        if (isBluetoothDisallowed()) {
        if (isBluetoothDisallowed()) {
            if (DBG) {
            if (DBG) {
                Slog.d(TAG,"enable(): not enabling - bluetooth disallowed");
                Slog.d(TAG,"enable(): not enabling - bluetooth disallowed");
@@ -677,14 +691,25 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            return false;
            return false;
        }
        }


        if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
        final int callingUid = Binder.getCallingUid();
            (!checkIfCallerIsForegroundUser())) {
        final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;

        if (!callerSystem) {
            if (!checkIfCallerIsForegroundUser()) {
                Slog.w(TAG, "enable(): not allowed for non-active and non system user");
                Slog.w(TAG, "enable(): not allowed for non-active and non system user");
                return false;
                return false;
            }
            }


            mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
            mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                    "Need BLUETOOTH ADMIN permission");
                    "Need BLUETOOTH ADMIN permission");

            if (!isEnabled() && mPermissionReviewRequired
                    && startConsentUiIfNeeded(packageName, callingUid,
                            BluetoothAdapter.ACTION_REQUEST_ENABLE)) {
                return false;
            }
        }

        if (DBG) {
        if (DBG) {
            Slog.d(TAG,"enable():  mBluetooth =" + mBluetooth +
            Slog.d(TAG,"enable():  mBluetooth =" + mBluetooth +
                    " mBinding = " + mBinding + " mState = " + mState);
                    " mBinding = " + mBinding + " mState = " + mState);
@@ -700,16 +725,26 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        return true;
        return true;
    }
    }


    public boolean disable(boolean persist) {
    public boolean disable(String packageName, boolean persist) throws RemoteException {
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
        final int callingUid = Binder.getCallingUid();
                                                "Need BLUETOOTH ADMIN permissicacheNameAndAddresson");
        final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;


        if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
        if (!callerSystem) {
            (!checkIfCallerIsForegroundUser())) {
            if (!checkIfCallerIsForegroundUser()) {
                Slog.w(TAG, "disable(): not allowed for non-active and non system user");
                Slog.w(TAG, "disable(): not allowed for non-active and non system user");
                return false;
                return false;
            }
            }


            mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                    "Need BLUETOOTH ADMIN permission");

            if (isEnabled() && mPermissionReviewRequired
                    && startConsentUiIfNeeded(packageName, callingUid,
                            BluetoothAdapter.ACTION_REQUEST_DISABLE)) {
                return false;
            }
        }

        if (DBG) {
        if (DBG) {
            Slog.d(TAG,"disable(): mBluetooth = " + mBluetooth +
            Slog.d(TAG,"disable(): mBluetooth = " + mBluetooth +
                " mBinding = " + mBinding);
                " mBinding = " + mBinding);
@@ -728,6 +763,31 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        return true;
        return true;
    }
    }


    private boolean startConsentUiIfNeeded(String packageName,
            int callingUid, String intentAction) throws RemoteException {
        try {
            // Validate the package only if we are going to use it
            ApplicationInfo applicationInfo = mContext.getPackageManager()
                    .getApplicationInfoAsUser(packageName,
                            PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                            UserHandle.getUserId(callingUid));
            if (applicationInfo.uid != callingUid) {
                throw new SecurityException("Package " + callingUid
                        + " not in uid " + callingUid);
            }

            // Legacy apps in permission review mode trigger a user prompt
            if (applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
                Intent intent = new Intent(intentAction);
                mContext.startActivity(intent);
                return true;
            }
        } catch (PackageManager.NameNotFoundException e) {
            throw new RemoteException(e.getMessage());
        }
        return false;
    }

    public void unbindAndFinish() {
    public void unbindAndFinish() {
        if (DBG) {
        if (DBG) {
            Slog.d(TAG,"unbindAndFinish(): " + mBluetooth +
            Slog.d(TAG,"unbindAndFinish(): " + mBluetooth +
+2 −2
Original line number Original line Diff line number Diff line
@@ -369,7 +369,7 @@ public final class ActiveServices {
        // we do not start the service and launch a review activity if the calling app
        // we do not start the service and launch a review activity if the calling app
        // is in the foreground passing it a pending intent to start the service when
        // is in the foreground passing it a pending intent to start the service when
        // review is completed.
        // review is completed.
        if (Build.PERMISSIONS_REVIEW_REQUIRED) {
        if (mAm.mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED) {
            if (!requestStartTargetPermissionsReviewIfNeededLocked(r, callingPackage,
            if (!requestStartTargetPermissionsReviewIfNeededLocked(r, callingPackage,
                    callingUid, service, callerFg, userId)) {
                    callingUid, service, callerFg, userId)) {
                return null;
                return null;
@@ -913,7 +913,7 @@ public final class ActiveServices {
        // we schedule binding to the service but do not start its process, then
        // we schedule binding to the service but do not start its process, then
        // we launch a review activity to which is passed a callback to invoke
        // we launch a review activity to which is passed a callback to invoke
        // when done to start the bound service's process to completing the binding.
        // when done to start the bound service's process to completing the binding.
        if (Build.PERMISSIONS_REVIEW_REQUIRED) {
        if (mAm.mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED) {
            if (mAm.getPackageManagerInternalLocked().isPermissionsReviewRequired(
            if (mAm.getPackageManagerInternalLocked().isPermissionsReviewRequired(
                    s.packageName, s.userId)) {
                    s.packageName, s.userId)) {


+6 −1
Original line number Original line Diff line number Diff line
@@ -1576,6 +1576,8 @@ public final class ActivityManagerService extends ActivityManagerNative
    // being called for multiwindow assist in a single session.
    // being called for multiwindow assist in a single session.
    private int mViSessionId = 1000;
    private int mViSessionId = 1000;
    final boolean mPermissionReviewRequired;
    final class KillHandler extends Handler {
    final class KillHandler extends Handler {
        static final int KILL_PROCESS_GROUP_MSG = 4000;
        static final int KILL_PROCESS_GROUP_MSG = 4000;
@@ -2623,6 +2625,9 @@ public final class ActivityManagerService extends ActivityManagerNative
        Slog.i(TAG, "Memory class: " + ActivityManager.staticGetMemoryClass());
        Slog.i(TAG, "Memory class: " + ActivityManager.staticGetMemoryClass());
        mPermissionReviewRequired = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_permissionReviewRequired);
        mHandlerThread = new ServiceThread(TAG,
        mHandlerThread = new ServiceThread(TAG,
                android.os.Process.THREAD_PRIORITY_FOREGROUND, false /*allowIo*/);
                android.os.Process.THREAD_PRIORITY_FOREGROUND, false /*allowIo*/);
        mHandlerThread.start();
        mHandlerThread.start();
@@ -10882,7 +10887,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    // If permissions need a review before any of the app components can run,
                    // If permissions need a review before any of the app components can run,
                    // we return no provider and launch a review activity if the calling app
                    // we return no provider and launch a review activity if the calling app
                    // is in the foreground.
                    // is in the foreground.
                    if (Build.PERMISSIONS_REVIEW_REQUIRED) {
                    if (mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED) {
                        if (!requestTargetProviderPermissionsReviewIfNeededLocked(cpi, r, userId)) {
                        if (!requestTargetProviderPermissionsReviewIfNeededLocked(cpi, r, userId)) {
                            return null;
                            return null;
                        }
                        }
Loading