Methods Summary |
---|
public void | addSettingsChangedCallback(LocationSettingsChangeCallback cb)Add a callback to listen for changes in location settings.
mSettingsChangeCallbacks.add(cb);
locationSettingsChanged(cb);
|
private boolean | areActiveHighPowerLocationRequests()Returns true if there currently exist active high power location requests.
List<AppOpsManager.PackageOps> packages
= mAppOpsManager.getPackagesForOps(mHighPowerRequestAppOpArray);
// AppOpsManager can return null when there is no requested data.
if (packages != null) {
final int numPackages = packages.size();
for (int packageInd = 0; packageInd < numPackages; packageInd++) {
AppOpsManager.PackageOps packageOp = packages.get(packageInd);
List<AppOpsManager.OpEntry> opEntries = packageOp.getOps();
if (opEntries != null) {
final int numOps = opEntries.size();
for (int opInd = 0; opInd < numOps; opInd++) {
AppOpsManager.OpEntry opEntry = opEntries.get(opInd);
// AppOpsManager should only return OP_MONITOR_HIGH_POWER_LOCATION because
// of the mHighPowerRequestAppOpArray filter, but checking defensively.
if (opEntry.getOp() == AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION) {
if (opEntry.isRunning()) {
return true;
}
}
}
}
}
}
return false;
|
public boolean | isLocationEnabled()Returns true if location isn't disabled in settings.
ContentResolver resolver = mContext.getContentResolver();
// QuickSettings always runs as the owner, so specifically retrieve the settings
// for the current foreground user.
int mode = Settings.Secure.getIntForUser(resolver, Settings.Secure.LOCATION_MODE,
Settings.Secure.LOCATION_MODE_OFF, ActivityManager.getCurrentUser());
return mode != Settings.Secure.LOCATION_MODE_OFF;
|
private boolean | isUserLocationRestricted(int userId)Returns true if the current user is restricted from using location.
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
return um.hasUserRestriction(
UserManager.DISALLOW_SHARE_LOCATION,
new UserHandle(userId));
|
private void | locationSettingsChanged()
boolean isEnabled = isLocationEnabled();
for (LocationSettingsChangeCallback cb : mSettingsChangeCallbacks) {
cb.onLocationSettingsChanged(isEnabled);
}
|
private void | locationSettingsChanged(LocationSettingsChangeCallback cb)
cb.onLocationSettingsChanged(isLocationEnabled());
|
public void | onReceive(android.content.Context context, android.content.Intent intent)
final String action = intent.getAction();
if (LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION.equals(action)) {
updateActiveLocationRequests();
}
|
private void | refreshViews()
if (mAreActiveLocationRequests) {
mStatusBarManager.setIcon(LOCATION_STATUS_ICON_PLACEHOLDER, LOCATION_STATUS_ICON_ID, 0,
mContext.getString(R.string.accessibility_location_active));
} else {
mStatusBarManager.removeIcon(LOCATION_STATUS_ICON_PLACEHOLDER);
}
|
public void | removeSettingsChangedCallback(LocationSettingsChangeCallback cb)
mSettingsChangeCallbacks.remove(cb);
|
public boolean | setLocationEnabled(boolean enabled)Enable or disable location in settings.
This will attempt to enable/disable every type of location setting
(e.g. high and balanced power).
If enabling, a user consent dialog will pop up prompting the user to accept.
If the user doesn't accept, network location won't be enabled.
int currentUserId = ActivityManager.getCurrentUser();
if (isUserLocationRestricted(currentUserId)) {
return false;
}
final ContentResolver cr = mContext.getContentResolver();
// When enabling location, a user consent dialog will pop up, and the
// setting won't be fully enabled until the user accepts the agreement.
int mode = enabled
? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY : Settings.Secure.LOCATION_MODE_OFF;
// QuickSettings always runs as the owner, so specifically set the settings
// for the current foreground user.
return Settings.Secure
.putIntForUser(cr, Settings.Secure.LOCATION_MODE, mode, currentUserId);
|
private void | updateActiveLocationRequests()
boolean hadActiveLocationRequests = mAreActiveLocationRequests;
mAreActiveLocationRequests = areActiveHighPowerLocationRequests();
if (mAreActiveLocationRequests != hadActiveLocationRequests) {
refreshViews();
}
|