Skip to content

Commit

Permalink
SecondScreen 2.7 (release 4)
Browse files Browse the repository at this point in the history
* Fix safe mode behaving incorrectly when in non-root mode and a profile requires a reboot
  • Loading branch information
farmerbb committed Mar 14, 2018
1 parent 2bab3f3 commit 7faed0c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 43 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
//noinspection OldTargetApi
targetSdkVersion 25

versionCode 171
versionCode 172
versionName "2.7"

resConfigs "en", "es", "fr", "sk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void onReceive(Context context, Intent intent) {
if(!prefCurrent.getBoolean("not_active", true)) {
if(prefMain.getBoolean("safe_mode", false)
&& !"activity-manager".equals(prefCurrent.getString("ui_refresh", "do-nothing"))
&& !prefCurrent.getBoolean("reboot_required", false)
&& prefCurrent.getLong("time_of_profile_start", 0)
< (System.currentTimeMillis() - (isDebugMode ? 0 : SystemClock.elapsedRealtime()))) {
SharedPreferences.Editor editor = prefCurrent.edit();
Expand All @@ -63,6 +64,7 @@ public void onReceive(Context context, Intent intent) {
} else if("quick_actions".equals(prefCurrent.getString("filename", "0"))) {
SharedPreferences prefSaved = U.getPrefQuickActions(context);
if("0".equals(prefSaved.getString("original_filename", "0"))
&& !prefCurrent.getBoolean("reboot_required", false)
&& prefCurrent.getLong("time_of_profile_start", 0)
< (System.currentTimeMillis() - (isDebugMode ? 0 : SystemClock.elapsedRealtime()))) {
SharedPreferences.Editor editor = prefCurrent.edit();
Expand All @@ -71,6 +73,8 @@ public void onReceive(Context context, Intent intent) {

U.turnOffProfile(context);
} else {
prefCurrent.edit().putBoolean("reboot_required", false).apply();

// Restore NotificationService
Intent serviceIntent = new Intent(context, NotificationService.class);
context.startService(serviceIntent);
Expand All @@ -80,6 +84,8 @@ public void onReceive(Context context, Intent intent) {
context.startService(serviceIntent2);
}
} else {
prefCurrent.edit().putBoolean("reboot_required", false).apply();

// Restore NotificationService
Intent serviceIntent = new Intent(context, NotificationService.class);
context.startService(serviceIntent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,34 @@ else if(shouldDisableTaskbarHome)
}
}

// Freeform windows
boolean rebootRequired = false;

if(prefCurrent.getBoolean("not_active", true))
editor.putBoolean("freeform_system", U.hasFreeformSupport(this));

if(prefSaved.getBoolean("freeform", false)) {
if(prefCurrent.getBoolean("not_active", true)) {
su[freeformCommand] = U.freeformCommand(true);
if(!U.hasFreeformSupport(this))
rebootRequired = true;
} else {
if(!prefCurrent.getBoolean("freeform", false)) {
su[freeformCommand] = U.freeformCommand(true);
if(!U.hasFreeformSupport(this))
rebootRequired = true;
}
}
} else {
if(!prefCurrent.getBoolean("not_active", true))
if(prefCurrent.getBoolean("freeform", false)) {
boolean freeformSystem = prefCurrent.getBoolean("freeform_system", false);
su[freeformCommand] = U.freeformCommand(freeformSystem);
if(U.hasFreeformSupport(this) != freeformSystem)
rebootRequired = true;
}
}

// Resolution and density

// Determine if CyanogenMod workaround is needed
Expand All @@ -250,7 +278,7 @@ else if(shouldDisableTaskbarHome)
&& Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1)
cmWorkaround = true;

String uiRefresh = cmWorkaround
String uiRefresh = (cmWorkaround || rebootRequired)
? "activity-manager"
: prefSaved.getString("ui_refresh", "do-nothing");

Expand Down Expand Up @@ -288,6 +316,11 @@ else if(shouldDisableTaskbarHome)
}
}

if(!rebootRequired) {
rebootRequired = uiRefresh.contains("activity-manager")
&& (shouldRunSizeCommand || shouldRunDensityCommand);
}

// Overscan
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
if(prefSaved.getBoolean("overscan", false)) {
Expand Down Expand Up @@ -568,35 +601,6 @@ else if(Settings.Secure.getInt(getContentResolver(), "screensaver_activate_on_sl
}
}

// Freeform windows
boolean rebootRequired = uiRefresh.contains("activity-manager")
&& (shouldRunSizeCommand || shouldRunDensityCommand);

if(prefCurrent.getBoolean("not_active", true))
editor.putBoolean("freeform_system", U.hasFreeformSupport(this));

if(prefSaved.getBoolean("freeform", false)) {
if(prefCurrent.getBoolean("not_active", true)) {
su[freeformCommand] = U.freeformCommand(true);
if(!rebootRequired && !U.hasFreeformSupport(this))
rebootRequired = true;
} else {
if(!prefCurrent.getBoolean("freeform", false)) {
su[freeformCommand] = U.freeformCommand(true);
if(!rebootRequired && !U.hasFreeformSupport(this))
rebootRequired = true;
}
}
} else {
if(!prefCurrent.getBoolean("not_active", true))
if(prefCurrent.getBoolean("freeform", false)) {
boolean freeformSystem = prefCurrent.getBoolean("freeform_system", false);
su[freeformCommand] = U.freeformCommand(freeformSystem);
if(!rebootRequired && (U.hasFreeformSupport(this) != freeformSystem))
rebootRequired = true;
}
}

// Backlight off

// If user has set "backlight off" in profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ private void turnOffProfile(SharedPreferences prefCurrent) {
}
}

// Freeform windows
boolean rebootRequired = false;

if(prefCurrent.getBoolean("freeform", true)) {
boolean freeformSystem = prefCurrent.getBoolean("freeform_system", false);
su[freeformCommand] = U.freeformCommand(freeformSystem);
if(U.hasFreeformSupport(this) != freeformSystem)
rebootRequired = true;
}

// Resolution and density

// Determine if CyanogenMod workaround is needed
Expand All @@ -169,7 +179,7 @@ private void turnOffProfile(SharedPreferences prefCurrent) {
&& Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1)
cmWorkaround = true;

String uiRefresh = cmWorkaround
String uiRefresh = (cmWorkaround || rebootRequired)
? "activity-manager"
: prefCurrent.getString("ui_refresh", "do-nothing");

Expand Down Expand Up @@ -203,6 +213,11 @@ private void turnOffProfile(SharedPreferences prefCurrent) {
}
}

if(!rebootRequired) {
rebootRequired = uiRefresh.contains("activity-manager")
&& (shouldRunSizeCommand || shouldRunDensityCommand);
}

// Overscan
if((Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) && prefCurrent.getBoolean("overscan", true))
su[overscanCommand] = U.overscanCommand + "reset";
Expand Down Expand Up @@ -304,17 +319,6 @@ private void turnOffProfile(SharedPreferences prefCurrent) {
if(!"do-nothing".equals(prefCurrent.getString("immersive_new", "do-nothing")))
su[immersiveCommand] = U.immersiveCommand("do-nothing");

// Freeform windows
boolean rebootRequired = uiRefresh.contains("activity-manager")
&& (shouldRunSizeCommand || shouldRunDensityCommand);

if(prefCurrent.getBoolean("freeform", true)) {
boolean freeformSystem = prefCurrent.getBoolean("freeform_system", false);
su[freeformCommand] = U.freeformCommand(freeformSystem);
if(!rebootRequired && (U.hasFreeformSupport(this) != freeformSystem))
rebootRequired = true;
}

// HDMI rotation
if(prefCurrent.getString("hdmi_rotation", "landscape").equals("portrait"))
su[hdmiRotationCommand] = U.hdmiRotationCommand + prefCurrent.getString("hdmi_rotation_system", "landscape");
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/farmerbb/secondscreen/util/U.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,10 @@ public static void runCommands(Context context, String[] commands, boolean reboo
}

if(rebootRequired) {
SharedPreferences prefCurrent = getPrefCurrent(context);
if(!prefCurrent.getBoolean("not_active", true))
prefCurrent.edit().putBoolean("reboot_required", true).apply();

Intent intent = new Intent(context, RebootRequiredActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Expand Down

0 comments on commit 7faed0c

Please sign in to comment.