Files
app_Settings/src/com/android/settings/applications/AppStateStorageAccessBridge.java
Felipe Leme 7a0ad2b30f Initial screens for Storage Access.
This new settings will be accessed through Apps -> Special Apps and it will let
users change the status of granted (or denied) Scoped Access Permissions.

This initial CL implements the landing activity that shows all packages and an
initial version of the detailed activity for a specific page, althouth the
detailed activity is not ready yet.

Test: manual verification
Test: export ROBOTEST_FILTER=com.android.settings.core.codeinspection.CodeInspectionTest && make RunSettingsRoboTests -j40
Bug: 63720392

Change-Id: Id0419c2c4aaaec365803218d6947e230e4776f13
2018-01-12 18:06:48 -08:00

89 lines
3.3 KiB
Java

/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications;
import static android.os.storage.StorageVolume.ScopedAccessProviderContract.AUTHORITY;
import static android.os.storage.StorageVolume.ScopedAccessProviderContract.TABLE_PACKAGES;
import static android.os.storage.StorageVolume.ScopedAccessProviderContract.TABLE_PACKAGES_COLUMNS;
import static android.os.storage.StorageVolume.ScopedAccessProviderContract.TABLE_PACKAGES_COL_PACKAGE;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.ArraySet;
import android.util.Log;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.applications.ApplicationsState.AppFilter;
import java.util.Set;
// TODO(b/63720392): add unit tests
public class AppStateStorageAccessBridge extends AppStateBaseBridge {
private static final String TAG = "StorageAccessBridge";
public AppStateStorageAccessBridge(ApplicationsState appState, Callback callback) {
super(appState, callback);
}
@Override
protected void loadAllExtraInfo() { }
@Override
protected void updateExtraInfo(AppEntry app, String pkg, int uid) { }
public static final AppFilter FILTER_APP_HAS_STORAGE_ACCESS = new AppFilter() {
private Set<String> mPackages;
@Override
public void init() {
throw new UnsupportedOperationException("Need to call constructor that takes context");
}
@Override
public void init(Context context) {
try (Cursor cursor = context.getContentResolver().query(
new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT)
.authority(AUTHORITY).appendPath(TABLE_PACKAGES).appendPath("*")
.build(), TABLE_PACKAGES_COLUMNS, null, null)) {
if (cursor == null) {
Log.w(TAG, "didn't get cursor");
return;
}
final int count = cursor.getCount();
if (count == 0) {
Log.d(TAG, "no packages");
return;
}
mPackages = new ArraySet<>(count);
while (cursor.moveToNext()) {
mPackages.add(cursor.getString(TABLE_PACKAGES_COL_PACKAGE));
}
Log.v(TAG, "init(): " + mPackages);
}
}
@Override
public boolean filterApp(AppEntry info) {
return mPackages != null && mPackages.contains(info.info.packageName);
}
};
}