feat: start re-enabling File Shuttle on Android R
* TODO: Figure out how to start the activity properly.
This commit is contained in:
parent
23c87cfe6e
commit
c147377c07
|
@ -11,7 +11,10 @@
|
|||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:maxSdkVersion="25"
|
||||
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
|
||||
|
||||
<application
|
||||
|
|
|
@ -21,6 +21,7 @@ interface IShelterService {
|
|||
void freezeApp(in ApplicationInfoWrapper app);
|
||||
void unfreezeApp(in ApplicationInfoWrapper app);
|
||||
boolean hasUsageStatsPermission();
|
||||
boolean hasAllFileAccessPermission();
|
||||
List<String> getCrossProfileWidgetProviders();
|
||||
boolean setCrossProfileWidgetProviderEnabled(String pkgName, boolean enabled);
|
||||
void setStartActivityProxy(in IStartActivityProxy proxy);
|
||||
|
|
|
@ -240,6 +240,11 @@ public class ShelterService extends Service {
|
|||
return Utility.checkUsageStatsPermission(ShelterService.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAllFileAccessPermission() {
|
||||
return Utility.checkAllFileAccessPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCrossProfileWidgetProviders() {
|
||||
if (!mIsProfileOwner)
|
||||
|
|
|
@ -536,11 +536,21 @@ public class DummyActivity extends Activity {
|
|||
}
|
||||
|
||||
private void actionStartFileShuttle() {
|
||||
// This requires the permission WRITE_EXTERNAL_STORAGE
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
doStartFileShuttle();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
// This requires the permission WRITE_EXTERNAL_STORAGE
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
doStartFileShuttle();
|
||||
} else {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION_EXTERNAL_STORAGE);
|
||||
}
|
||||
} else {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION_EXTERNAL_STORAGE);
|
||||
// The all file access permission should have been granted when enabling File Shuttle
|
||||
// since Android R.
|
||||
if (Utility.checkAllFileAccessPermission()) {
|
||||
doStartFileShuttle();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,8 +86,8 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
|
|||
mPrefSkipForeground.setOnPreferenceChangeListener(this);
|
||||
|
||||
// Disable FileSuttle on Q for now
|
||||
// TODO: Refactor FileShuttle and remove this
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
// Supported on R and beyond
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
|
||||
mPrefCrossProfileFileChooser.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +122,27 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
|
|||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newState) {
|
||||
if (preference == mPrefCrossProfileFileChooser) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
// Request all files permission on R and beyond
|
||||
boolean hasPermission = false;
|
||||
try {
|
||||
hasPermission = mServiceWork.hasAllFileAccessPermission() && Utility.checkAllFileAccessPermission();
|
||||
} catch (RemoteException e) {
|
||||
|
||||
}
|
||||
|
||||
if (!hasPermission) {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setMessage(R.string.request_storage_manager)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
(dialog, which) -> startActivity(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)))
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
(dialog, which) -> dialog.dismiss())
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
mManager.setCrossProfileFileChooserEnabled((boolean) newState);
|
||||
return true;
|
||||
} else if (preference == mPrefCameraProxy) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.graphics.drawable.BitmapDrawable;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.UserManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.Settings;
|
||||
|
@ -378,6 +379,12 @@ public class Utility {
|
|||
return checkSpecialAccessPermission(context, AppOpsManager.OPSTR_GET_USAGE_STATS);
|
||||
}
|
||||
|
||||
// Check if all file access r/w is granted
|
||||
@TargetApi(Build.VERSION_CODES.R)
|
||||
public static boolean checkAllFileAccessPermission() {
|
||||
return Environment.isExternalStorageManager();
|
||||
}
|
||||
|
||||
// Check special access permission through AppOps
|
||||
public static boolean checkSpecialAccessPermission(Context context, String name) {
|
||||
AppOpsManager appops = context.getSystemService(AppOpsManager.class);
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
<string name="shortcut_create_success">Shortcut created on your launcher.</string>
|
||||
<string name="request_usage_stats">Shelter needs <b>Usage Stats</b> permission to do this. Please enable the permission for <b>BOTH OF THE TWO</b> Shelter apps shown in the dialog after you press \"Ok\". Failing to do so will cause this feature to not work properly.</string>
|
||||
<string name="launch_app_fail">Cannot launch app %s because it has no GUI.</string>
|
||||
<string name="request_storage_manager">Shelter needs access to <b>All Files</b> for File Shuttle. Please enable the permission for <b>BOTH OF THE TWO </b> (Personal / Work) Shelter apps shown in the dialog after you press \"Ok\".</string>
|
||||
|
||||
<!-- MIUI -->
|
||||
<string name="miui_cannot_clone">Cloning non-system apps to another profile is currently not possible on MIUI. Please clone your system\'s app store (e.g. <b>Play Store</b>) into the other profile and then install apps from there.</string>
|
||||
|
|
Loading…
Reference in New Issue