Location Setting change for O
This is a change that adds a link from location settings to location permissions Test: Manual Bug: 34400189 Change-Id: If873fbb6e53c1fd86a3cfe38e06465cdec56bef8
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package com.android.settings.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
|
||||
public class AppLocationPermissionPreferenceController extends PreferenceController {
|
||||
|
||||
private static final String KEY_APP_LEVEL_PERMISSIONS = "app_level_permissions";
|
||||
private Preference mPreference;
|
||||
|
||||
public AppLocationPermissionPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (isAvailable()) {
|
||||
mPreference = screen.findPreference(KEY_APP_LEVEL_PERMISSIONS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_APP_LEVEL_PERMISSIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||
android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED, 1)
|
||||
== 1;
|
||||
}
|
||||
}
|
@@ -18,6 +18,7 @@ package com.android.settings.location;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -95,11 +96,14 @@ public class LocationSettings extends LocationSettingsBase
|
||||
private static final String KEY_LOCATION_MODE = "location_mode";
|
||||
/** Key for preference category "Recent location requests" */
|
||||
private static final String KEY_RECENT_LOCATION_REQUESTS = "recent_location_requests";
|
||||
/** Key for preference "App-level permissions" */
|
||||
private static final String KEY_APP_LEVEL_PERMISSIONS = "app_level_permissions";
|
||||
/** Key for preference category "Location services" */
|
||||
private static final String KEY_LOCATION_SERVICES = "location_services";
|
||||
|
||||
private static final int MENU_SCANNING = Menu.FIRST;
|
||||
|
||||
private static final String KEY_LOCATION_PERMISSION = "android.permission-group.LOCATION";
|
||||
private SwitchBar mSwitchBar;
|
||||
private Switch mSwitch;
|
||||
private boolean mValidListener = false;
|
||||
@@ -201,10 +205,21 @@ public class LocationSettings extends LocationSettingsBase
|
||||
}
|
||||
});
|
||||
|
||||
mCategoryRecentLocationRequests =
|
||||
(PreferenceCategory) root.findPreference(KEY_RECENT_LOCATION_REQUESTS);
|
||||
RecentLocationApps recentApps = new RecentLocationApps(activity);
|
||||
List<RecentLocationApps.Request> recentLocationRequests = recentApps.getAppList();
|
||||
|
||||
final AppLocationPermissionPreferenceController preferenceController =
|
||||
new AppLocationPermissionPreferenceController(activity);
|
||||
preferenceController.displayPreference(root);
|
||||
if (preferenceController.isAvailable()) {
|
||||
Preference preferenceAppLevelPermissions =
|
||||
root.findPreference(KEY_APP_LEVEL_PERMISSIONS);
|
||||
setupAppLevelPermissionsPreference(preferenceAppLevelPermissions);
|
||||
}
|
||||
|
||||
mCategoryRecentLocationRequests =
|
||||
(PreferenceCategory) root.findPreference(KEY_RECENT_LOCATION_REQUESTS);
|
||||
|
||||
List<Preference> recentLocationPrefs = new ArrayList<>(recentLocationRequests.size());
|
||||
for (final RecentLocationApps.Request request : recentLocationRequests) {
|
||||
DimmableIconPreference pref = new DimmableIconPreference(getPrefContext(),
|
||||
@@ -261,6 +276,23 @@ public class LocationSettings extends LocationSettingsBase
|
||||
}
|
||||
}
|
||||
|
||||
private void setupAppLevelPermissionsPreference(Preference preference) {
|
||||
preference.setOnPreferenceClickListener(
|
||||
new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent = new Intent(Intent.ACTION_MANAGE_PERMISSION_APPS)
|
||||
.putExtra(Intent.EXTRA_PERMISSION_NAME, KEY_LOCATION_PERMISSION);
|
||||
try {
|
||||
getActivity().startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w("Permission", "No app to handle " + intent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void changeManagedProfileLocationAccessStatus(boolean mainSwitchOn) {
|
||||
if (mManagedProfileSwitch == null) {
|
||||
return;
|
||||
|
Reference in New Issue
Block a user