Skip to content

Commit

Permalink
Merge pull request #3737 from TeamAmaze/feature/sdk33
Browse files Browse the repository at this point in the history
SDK 33 adaptations, language and library upgrades
  • Loading branch information
VishalNehra authored Oct 30, 2023
2 parents 0fef0d4 + faf28bb commit 58b4ff0
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 71 deletions.
24 changes: 13 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'com.hiya.jacoco-android'
apply plugin: "com.starter.easylauncher"

android {
compileSdkVersion 31
compileSdkVersion 33
packagingOptions {
resources {
excludes += ['proguard-project.txt', 'project.properties', 'META-INF/LICENSE.txt', 'META-INF/LICENSE', 'META-INF/NOTICE.txt', 'META-INF/NOTICE', 'META-INF/DEPENDENCIES.txt', 'META-INF/DEPENDENCIES']
Expand All @@ -17,7 +17,7 @@ android {
defaultConfig {
applicationId "com.amaze.filemanager"
minSdkVersion 19
targetSdkVersion 31
targetSdkVersion 33
versionCode 118
versionName "3.8.5"
multiDexEnabled true
Expand Down Expand Up @@ -85,13 +85,12 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '1.8'
useIR = true
jvmTarget = '11'
}

testOptions {
Expand Down Expand Up @@ -252,14 +251,18 @@ dependencies {

}

kotlin {
jvmToolchain(11)
}

configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module("commons-logging:commons-logging-api:1.1") with module("commons-logging:commons-logging:1.1.1")
substitute module("com.android.support:support-annotations:27.1.1") with module("com.android.support:support-annotations:27.0.2")
substitute module("commons-logging:commons-logging-api:1.1") using module("commons-logging:commons-logging:1.1.1")
substitute module("com.android.support:support-annotations:27.1.1") using module("com.android.support:support-annotations:27.0.2")
// These two lines are added to prevent possible class clashes between awaitility (which uses hamcrest 2.1) and junit (which uses hamcrest 1.3).
substitute module('org.hamcrest:hamcrest-core:1.3') with module("org.hamcrest:hamcrest:2.1")
substitute module('org.hamcrest:hamcrest-library:1.3') with module("org.hamcrest:hamcrest:2.1")
substitute module('org.hamcrest:hamcrest-core:1.3') using module("org.hamcrest:hamcrest:2.1")
substitute module('org.hamcrest:hamcrest-library:1.3') using module("org.hamcrest:hamcrest:2.1")
}
}
}
Expand Down Expand Up @@ -306,7 +309,6 @@ tasks.withType(Test) {
jacoco.excludes = ['jdk.internal.*']
}


Properties props = new Properties()
def propFile = new File('signing.properties')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class SecretKeygenEspressoTest {
assertEquals("aes", this.algorithm.lowercase())
} ?: if (SDK_INT < ICE_CREAM_SANDWICH) {
fail("Android version not supported")
} else {
// do nothing
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -39,6 +40,7 @@
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-feature
android:name="android.hardware.touchscreen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,16 @@ public void onPermissionGranted() {
}

private void checkForExternalPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (SDK_INT >= Build.VERSION_CODES.M) {
if (!checkStoragePermission()) {
requestStoragePermission(this, true);
if (SDK_INT >= Build.VERSION_CODES.R) {
requestAllFilesAccess(this);
} else {
requestStoragePermission(this, true);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
requestAllFilesAccess(this);
if (SDK_INT >= Build.VERSION_CODES.TIRAMISU && !checkNotificationPermission()) {
requestNotificationPermission(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

package com.amaze.filemanager.ui.activities.superclasses;

import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.TIRAMISU;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.amaze.filemanager.R;
Expand Down Expand Up @@ -48,10 +51,11 @@ public class PermissionsActivity extends ThemedActivity

private static final String TAG = PermissionsActivity.class.getSimpleName();

public static final int PERMISSION_LENGTH = 3;
public static final int PERMISSION_LENGTH = 4;
public static final int STORAGE_PERMISSION = 0,
INSTALL_APK_PERMISSION = 1,
ALL_FILES_PERMISSION = 2;
ALL_FILES_PERMISSION = 2,
NOTIFICATION_PERMISSION = 3;

private final OnPermissionGranted[] permissionCallbacks =
new OnPermissionGranted[PERMISSION_LENGTH];
Expand All @@ -69,7 +73,13 @@ public void onRequestPermissionsResult(
Toast.makeText(this, R.string.grantfailed, Toast.LENGTH_SHORT).show();
requestStoragePermission(permissionCallbacks[STORAGE_PERMISSION], false);
}

} else if (requestCode == NOTIFICATION_PERMISSION && SDK_INT >= TIRAMISU) {
if (isGranted(grantResults)) {
Utils.enableScreenRotation(this);
} else {
Toast.makeText(this, R.string.grantfailed, Toast.LENGTH_SHORT).show();
requestNotificationPermission(false);
}
} else if (requestCode == INSTALL_APK_PERMISSION) {
if (isGranted(grantResults)) {
permissionCallbacks[INSTALL_APK_PERMISSION].onPermissionGranted();
Expand All @@ -80,10 +90,45 @@ public void onRequestPermissionsResult(

public boolean checkStoragePermission() {
// Verify that all required contact permissions have been granted.
return ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
if (SDK_INT >= Build.VERSION_CODES.R) {
return ActivityCompat.checkSelfPermission(
this, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
== PackageManager.PERMISSION_GRANTED;
} else {
return ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
}
}

@RequiresApi(TIRAMISU)
public boolean checkNotificationPermission() {
return ActivityCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS)
== PackageManager.PERMISSION_GRANTED;
}

@RequiresApi(TIRAMISU)
public void requestNotificationPermission(boolean isInitialStart) {
Utils.disableScreenRotation(this);
final MaterialDialog materialDialog =
GeneralDialogCreation.showBasicDialog(
this,
R.string.grant_notification_permission,
R.string.grantper,
R.string.grant,
R.string.cancel);
materialDialog.getActionButton(DialogAction.NEGATIVE).setOnClickListener(v -> finish());
materialDialog.setCancelable(false);

requestPermission(
Manifest.permission.POST_NOTIFICATIONS,
NOTIFICATION_PERMISSION,
materialDialog,
() -> {
// do nothing
},
isInitialStart);
}

public void requestStoragePermission(
@NonNull final OnPermissionGranted onPermissionGranted, boolean isInitialStart) {
Utils.disableScreenRotation(this);
Expand Down Expand Up @@ -160,18 +205,27 @@ private void requestPermission(
} else if (isInitialStart) {
ActivityCompat.requestPermissions(this, new String[] {permission}, code);
} else {
Snackbar.make(
findViewById(R.id.content_frame),
R.string.grantfailed,
BaseTransientBottomBar.LENGTH_INDEFINITE)
.setAction(
R.string.grant,
v ->
startActivity(
new Intent(
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.parse(String.format("package:%s", getPackageName())))))
.show();
if (SDK_INT >= Build.VERSION_CODES.R) {
Snackbar.make(
findViewById(R.id.content_frame),
R.string.grantfailed,
BaseTransientBottomBar.LENGTH_INDEFINITE)
.setAction(R.string.grant, v -> requestAllFilesAccessPermission(onPermissionGranted))
.show();
} else {
Snackbar.make(
findViewById(R.id.content_frame),
R.string.grantfailed,
BaseTransientBottomBar.LENGTH_INDEFINITE)
.setAction(
R.string.grant,
v ->
startActivity(
new Intent(
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.parse(String.format("package:%s", getPackageName())))))
.show();
}
}
}

Expand All @@ -194,24 +248,30 @@ public void requestAllFilesAccess(@NonNull final OnPermissionGranted onPermissio
.getActionButton(DialogAction.POSITIVE)
.setOnClickListener(
v -> {
Utils.disableScreenRotation(this);
permissionCallbacks[ALL_FILES_PERMISSION] = onPermissionGranted;
try {
Intent intent =
new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "Failed to initial activity to grant all files access", e);
AppConfig.toast(this, getString(R.string.grantfailed));
}
requestAllFilesAccessPermission(onPermissionGranted);
materialDialog.dismiss();
});
materialDialog.setCancelable(false);
materialDialog.show();
}
}

@RequiresApi(api = Build.VERSION_CODES.R)
private void requestAllFilesAccessPermission(
@NonNull final OnPermissionGranted onPermissionGranted) {
Utils.disableScreenRotation(this);
permissionCallbacks[ALL_FILES_PERMISSION] = onPermissionGranted;
try {
Intent intent =
new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "Failed to initial activity to grant all files access", e);
AppConfig.toast(this, getString(R.string.grantfailed));
}
}

private boolean isGranted(int[] grantResults) {
return grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ open class BaseBottomSheetFragment : BottomSheetDialogFragment() {
* Initializes bottom sheet ui resources based on current theme
*/
fun initDialogResources(rootView: View) {
when ((activity as ThemedActivity?)!!.appTheme!!) {
when ((requireActivity() as ThemedActivity).appTheme!!) {
AppTheme.DARK -> {
rootView.setBackgroundDrawable(
context?.resources?.getDrawable(
Expand All @@ -54,7 +54,7 @@ open class BaseBottomSheetFragment : BottomSheetDialogFragment() {
)
)
}
AppTheme.LIGHT, AppTheme.TIMED -> {
AppTheme.LIGHT, AppTheme.TIMED, AppTheme.SYSTEM -> {
rootView
.setBackgroundDrawable(
context?.resources?.getDrawable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import android.view.MenuItem
data class HasherOfMenuItem(
val groupId: Int,
val itemId: Int,
val title: CharSequence,
val title: CharSequence?,
val ordering: Int
)

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ You only need to do this once, until the next time you select a new location for
<string name="try_indexed_search">Try Indexed Search!</string>
<string name="search_recent">Recent</string>
<string name="results">Results</string>
<string name="grant_notification_permission">Amaze needs notification permission to display file operation progress, as well as a handy panel to start/stop the FTP server.</string>
<string name="error_unsupported_or_null_uri">Invalid, unsupported, or no URI was provided</string>
<string name="complete_paste_warning">Please complete paste operation first</string>
<string name="same_dir_move_error">Destination and source folder shouldn\'t match to move.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,15 @@ static class MigratingDelegate extends MigrationTestHelper.RoomOpenHelperDelegat
}

@Override
protected void createAllTables(SupportSQLiteDatabase database) {
public void createAllTables(SupportSQLiteDatabase database) {
throw new UnsupportedOperationException(
"Was expecting to migrate but received create."
+ "Make sure you have created the database first.");
}

@NonNull
@Override
protected RoomOpenHelper.ValidationResult onValidateSchema(@NonNull SupportSQLiteDatabase db) {
public RoomOpenHelper.ValidationResult onValidateSchema(@NonNull SupportSQLiteDatabase db) {
final Map<String, EntityBundle> tables = mDatabaseBundle.getEntitiesByTableName();
for (EntityBundle entity : tables.values()) {
if (entity instanceof FtsEntityBundle) {
Expand Down Expand Up @@ -548,15 +548,15 @@ static class CreatingDelegate extends MigrationTestHelper.RoomOpenHelperDelegate
}

@Override
protected void createAllTables(SupportSQLiteDatabase database) {
public void createAllTables(SupportSQLiteDatabase database) {
for (String query : mDatabaseBundle.buildCreateQueries()) {
database.execSQL(query);
}
}

@NonNull
@Override
protected RoomOpenHelper.ValidationResult onValidateSchema(@NonNull SupportSQLiteDatabase db) {
public RoomOpenHelper.ValidationResult onValidateSchema(@NonNull SupportSQLiteDatabase db) {
throw new UnsupportedOperationException(
"This open helper just creates the database but" + " it received a migration request.");
}
Expand All @@ -571,14 +571,14 @@ abstract static class RoomOpenHelperDelegate extends RoomOpenHelper.Delegate {
}

@Override
protected void dropAllTables(SupportSQLiteDatabase database) {
public void dropAllTables(SupportSQLiteDatabase database) {
throw new UnsupportedOperationException("cannot drop all tables in the test");
}

@Override
protected void onCreate(SupportSQLiteDatabase database) {}
public void onCreate(SupportSQLiteDatabase database) {}

@Override
protected void onOpen(SupportSQLiteDatabase database) {}
public void onOpen(SupportSQLiteDatabase database) {}
}
}
Loading

0 comments on commit 58b4ff0

Please sign in to comment.