Don't try to lock screen orientation in SecurityTokenOperationActivity on Android 8.0

This commit is contained in:
Vincent Breitmoser 2018-07-18 16:01:53 +02:00
parent 4231279aba
commit a4b1751da4
3 changed files with 14 additions and 34 deletions

View file

@ -78,7 +78,7 @@ public class SecurityTokenChangePinOperationActivity extends BaseSecurityTokenAc
nfcGuideView = findViewById(R.id.nfc_guide_view); nfcGuideView = findViewById(R.id.nfc_guide_view);
// prevent annoying orientation changes while fumbling with the device // prevent annoying orientation changes while fumbling with the device
OrientationUtils.lockOrientation(this); OrientationUtils.lockCurrentOrientation(this);
// prevent close when touching outside of the dialog (happens easily when fumbling with the device) // prevent close when touching outside of the dialog (happens easily when fumbling with the device)
setFinishOnTouchOutside(false); setFinishOnTouchOutside(false);
// keep screen on // keep screen on

View file

@ -96,7 +96,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity {
nfcGuideView = findViewById(R.id.nfc_guide_view); nfcGuideView = findViewById(R.id.nfc_guide_view);
// prevent annoying orientation changes while fumbling with the device // prevent annoying orientation changes while fumbling with the device
OrientationUtils.lockOrientation(this); OrientationUtils.lockCurrentOrientation(this);
// prevent close when touching outside of the dialog (happens easily when fumbling with the device) // prevent close when touching outside of the dialog (happens easily when fumbling with the device)
setFinishOnTouchOutside(false); setFinishOnTouchOutside(false);
// keep screen on // keep screen on

View file

@ -17,39 +17,27 @@
package org.sufficientlysecure.keychain.util; package org.sufficientlysecure.keychain.util;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.view.Display; import android.view.Display;
import android.view.Surface; import android.view.Surface;
import android.view.WindowManager; import android.view.WindowManager;
/**
* Static methods related to device orientation.
*/
public class OrientationUtils { public class OrientationUtils {
public static void lockCurrentOrientation(Activity activity) {
/** // locking orientation for non-fullscreen activities is restricted in *exactly* Android 8.0.
* Locks the device window in landscape mode. // see https://github.com/aosp-mirror/platform_frameworks_base/commit/39791594560b2326625b663ed6796882900c220f#diff-960c6fdd4a4b336d98b785268b2a78ff
*/ // But apparently, they changed their mind in 8.1 again
public static void lockOrientationLandscape(Activity activity) { // and https://github.com/aosp-mirror/platform_frameworks_base/commit/d4ecffae67fa0dea03c581ca26f76b87a14be763#diff-960c6fdd4a4b336d98b785268b2a78ff
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); if (VERSION.SDK_INT == VERSION_CODES.O) {
} return;
}
/** Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
* Locks the device window in portrait mode.
*/
public static void lockOrientationPortrait(Activity activity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
/**
* Locks the device window in actual screen mode.
*/
public static void lockOrientation(Activity activity) {
Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
int rotation = display.getRotation(); int rotation = display.getRotation();
int tempOrientation = activity.getResources().getConfiguration().orientation; int tempOrientation = activity.getResources().getConfiguration().orientation;
int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
@ -74,12 +62,4 @@ public class OrientationUtils {
} }
activity.setRequestedOrientation(orientation); activity.setRequestedOrientation(orientation);
} }
/**
* Unlocks the device window in user defined screen mode.
*/
public static void unlockOrientation(Activity activity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
}
} }