Merge "Don't offer the BT sharing option to the user if BT is disallowed." am: 2c1e396382
am: c0118ac10e
Change-Id: I2aede50aba4c693f6bc45d2e53a0f4b7d8303c32
This commit is contained in:
@@ -50,6 +50,7 @@ import android.os.Message;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.RemoteCallbackList;
|
import android.os.RemoteCallbackList;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.ServiceManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
@@ -59,6 +60,8 @@ import android.provider.Settings;
|
|||||||
import android.provider.Settings.SettingNotFoundException;
|
import android.provider.Settings.SettingNotFoundException;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
|
import com.android.server.pm.PackageManagerService;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -218,6 +221,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void onUserRestrictionsChanged(int userId, Bundle newRestrictions,
|
public void onUserRestrictionsChanged(int userId, Bundle newRestrictions,
|
||||||
Bundle prevRestrictions) {
|
Bundle prevRestrictions) {
|
||||||
|
if (!newRestrictions.containsKey(UserManager.DISALLOW_BLUETOOTH)
|
||||||
|
&& !prevRestrictions.containsKey(UserManager.DISALLOW_BLUETOOTH)) {
|
||||||
|
// The relevant restriction has not changed - do nothing.
|
||||||
|
return;
|
||||||
|
}
|
||||||
final boolean bluetoothDisallowed =
|
final boolean bluetoothDisallowed =
|
||||||
newRestrictions.getBoolean(UserManager.DISALLOW_BLUETOOTH);
|
newRestrictions.getBoolean(UserManager.DISALLOW_BLUETOOTH);
|
||||||
if ((mEnable || mEnableExternal) && bluetoothDisallowed) {
|
if ((mEnable || mEnableExternal) && bluetoothDisallowed) {
|
||||||
@@ -228,6 +236,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
// when from system.
|
// when from system.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateOppLauncherComponentState(bluetoothDisallowed);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -949,7 +958,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
UserManagerInternal userManagerInternal =
|
UserManagerInternal userManagerInternal =
|
||||||
LocalServices.getService(UserManagerInternal.class);
|
LocalServices.getService(UserManagerInternal.class);
|
||||||
userManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener);
|
userManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener);
|
||||||
if (isBluetoothDisallowed()) {
|
final boolean isBluetoothDisallowed = isBluetoothDisallowed();
|
||||||
|
PackageManagerService packageManagerService =
|
||||||
|
(PackageManagerService) ServiceManager.getService("package");
|
||||||
|
if (packageManagerService != null && !packageManagerService.isOnlyCoreApps()) {
|
||||||
|
updateOppLauncherComponentState(isBluetoothDisallowed);
|
||||||
|
}
|
||||||
|
if (isBluetoothDisallowed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mEnableExternal && isBluetoothPersistedStateOnBluetooth()) {
|
if (mEnableExternal && isBluetoothPersistedStateOnBluetooth()) {
|
||||||
@@ -2006,6 +2021,28 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables BluetoothOppLauncherActivity component, so the Bluetooth sharing option is not
|
||||||
|
* offered to the user if Bluetooth is disallowed. Puts the component to its default state if
|
||||||
|
* Bluetooth is not disallowed.
|
||||||
|
*
|
||||||
|
* @param bluetoothDisallowed whether the {@link UserManager.DISALLOW_BLUETOOTH} user
|
||||||
|
* restriction was set.
|
||||||
|
*/
|
||||||
|
private void updateOppLauncherComponentState(boolean bluetoothDisallowed) {
|
||||||
|
final ComponentName oppLauncherComponent = new ComponentName("com.android.bluetooth",
|
||||||
|
"com.android.bluetooth.opp.BluetoothOppLauncherActivity");
|
||||||
|
final int newState = bluetoothDisallowed
|
||||||
|
? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||||
|
: PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
|
||||||
|
try {
|
||||||
|
mContext.getPackageManager()
|
||||||
|
.setComponentEnabledSetting(oppLauncherComponent, newState, 0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// The component was not found, do nothing.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
|
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
|
||||||
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
|
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
|
||||||
|
|||||||
Reference in New Issue
Block a user