Update location app stats
- Count apps in both primary and work profiles - Show the number of any location permitted app instead of background allowed apps on Location settings page - Update the text at the top-level settings page Bug: 129296799 Bug: 129358133 Bug: 129358508 Bug: 131432116 Test: build, flash, and test manually Change-Id: I1a4284257a8a284140b81685efc98a2cc4a74619
This commit is contained in:
@@ -8,18 +8,23 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.location.LocationManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.permission.PermissionControllerManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class TopLevelLocationPreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
@@ -28,8 +33,10 @@ public class TopLevelLocationPreferenceController extends BasePreferenceControll
|
||||
private final LocationManager mLocationManager;
|
||||
/** Total number of apps that has location permission. */
|
||||
private int mNumTotal = -1;
|
||||
private int mNumTotalLoading = 0;
|
||||
private BroadcastReceiver mReceiver;
|
||||
private Preference mPreference;
|
||||
private AtomicInteger loadingInProgress = new AtomicInteger(0);
|
||||
|
||||
public TopLevelLocationPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
@@ -66,16 +73,37 @@ public class TopLevelLocationPreferenceController extends BasePreferenceControll
|
||||
super.updateState(preference);
|
||||
mPreference = preference;
|
||||
refreshSummary(preference);
|
||||
// Bail out if location has been disabled.
|
||||
if (!mLocationManager.isLocationEnabled()) {
|
||||
// Bail out if location has been disabled, or there's another loading request in progress.
|
||||
if (!mLocationManager.isLocationEnabled() ||
|
||||
loadingInProgress.get() != 0) {
|
||||
return;
|
||||
}
|
||||
mContext.getSystemService(PermissionControllerManager.class).countPermissionApps(
|
||||
Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION),
|
||||
PermissionControllerManager.COUNT_ONLY_WHEN_GRANTED,
|
||||
(numApps) -> {
|
||||
setLocationAppCount(numApps);
|
||||
}, null);
|
||||
mNumTotalLoading = 0;
|
||||
// Retrieve a list of users inside the current user profile group.
|
||||
final List<UserHandle> users = mContext.getSystemService(
|
||||
UserManager.class).getUserProfiles();
|
||||
loadingInProgress.set(users.size());
|
||||
for (UserHandle user : users) {
|
||||
final Context userContext = Utils.createPackageContextAsUser(mContext,
|
||||
user.getIdentifier());
|
||||
if (userContext == null) {
|
||||
if (loadingInProgress.decrementAndGet() == 0) {
|
||||
setLocationAppCount(mNumTotalLoading);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
final PermissionControllerManager permController =
|
||||
userContext.getSystemService(PermissionControllerManager.class);
|
||||
permController.countPermissionApps(
|
||||
Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION),
|
||||
PermissionControllerManager.COUNT_ONLY_WHEN_GRANTED,
|
||||
(numApps) -> {
|
||||
mNumTotalLoading += numApps;
|
||||
if (loadingInProgress.decrementAndGet() == 0) {
|
||||
setLocationAppCount(mNumTotalLoading);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,7 +126,8 @@ public class TopLevelLocationPreferenceController extends BasePreferenceControll
|
||||
}
|
||||
|
||||
private void refreshLocationMode() {
|
||||
// 'null' is checked inside updateState(), so no need to check here.
|
||||
updateState(mPreference);
|
||||
if (mPreference != null) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user