Skip to content

Commit

Permalink
Double confirm if our service is registered into system
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed May 30, 2019
1 parent 741443f commit 75aa7ac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

// This is a workaround that some apps is installed on SD.
// We trigger a package scan now, to ensure wo got all packages.
if (XAPMManager.get().isServiceAvailable()) {
if (XAPMManager.get().isServiceAvailable(true)) {
XAPMManager.get().forceReloadPackages();
}

Expand Down Expand Up @@ -191,7 +191,7 @@ private void miscIfNotFirst() {
}

private void loadAppLockConfig() {
if (XAPMManager.get().isServiceAvailable()) {
if (XAPMManager.get().isServiceAvailable(true)) {
XExecutor.execute(() -> {
String[] whitelist = getResources().getStringArray(R.array.app_lock_white_list_activity);
XAPMManager.get().addAppLockWhiteListActivity(whitelist);
Expand Down Expand Up @@ -289,7 +289,7 @@ protected void onResume() {
}

private void checkForRedemptionMode() {
boolean redemption = XAPMManager.get().isServiceAvailable()
boolean redemption = XAPMManager.get().isServiceAvailable(true)
&& XAPMManager.get().isInRedemptionMode();
if (redemption) {
new AlertDialog.Builder(getActivity())
Expand Down Expand Up @@ -585,7 +585,7 @@ private void setupView() {

ViewGroup header = findView(rootView, R.id.header1);
header.setBackgroundColor(
XAppLockManager.get().isServiceAvailable() ?
XAppLockManager.get().isServiceAvailable(true) ?
cardAccentColor
: ContextCompat.getColor(getActivity(), R.color.red));
imageView.setImageResource(isServiceAvailable()
Expand Down Expand Up @@ -626,7 +626,7 @@ private void buildSuggestions() {
}

// Active!
if (!XAPMManager.get().isServiceAvailable()) {
if (!XAPMManager.get().isServiceAvailable(true)) {
Suggestion suggestion = new Suggestion(
getString(R.string.suggestion_active),
getString(R.string.suggestion_summary_active),
Expand All @@ -649,7 +649,7 @@ private void buildSuggestions() {

// Donate
boolean isPlayVersion = XAppBuildVar.BUILD_VARS.contains(XAppBuildVar.PLAY);
if (!isPlayVersion && XAPMManager.get().isServiceAvailable() && !AppSettings.isDonated(getActivity())) {
if (!isPlayVersion && XAPMManager.get().isServiceAvailable(true) && !AppSettings.isDonated(getActivity())) {
Suggestion suggestion = new Suggestion(
getString(R.string.suggestion_donate),
getString(R.string.suggestion_summary_donate,
Expand All @@ -667,7 +667,7 @@ private void buildSuggestions() {
}

// Debug mode.
if (XAppLockManager.get().isServiceAvailable() && XAppLockManager.get().isDebug()) {
if (XAppLockManager.get().isServiceAvailable(true) && XAppLockManager.get().isDebug()) {
Suggestion suggestion = new Suggestion(
getString(R.string.suggestion_turn_off_debug_mode),
getString(R.string.suggestion_summary_turn_off_debug_mode),
Expand All @@ -681,7 +681,7 @@ private void buildSuggestions() {
}

// Power save.
if (XAPMManager.get().isServiceAvailable() && !XAPMManager.get().isPowerSaveModeEnabled()) {
if (XAPMManager.get().isServiceAvailable(true) && !XAPMManager.get().isPowerSaveModeEnabled()) {
Suggestion suggestion = new Suggestion(
getString(R.string.suggestion_turn_on_power_save),
getString(R.string.suggestion_summary_turn_on_power_save),
Expand Down Expand Up @@ -734,7 +734,7 @@ private void onRequestUninstalledAPM() {
.setTitle(R.string.title_uninstall_apm)
.setMessage(getString(R.string.message_uninstall_apm))
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
if (XAPMManager.get().isServiceAvailable()) {
if (XAPMManager.get().isServiceAvailable(true)) {
XAPMManager.get().restoreDefaultSettings();
Toast.makeText(getContext(), R.string.summary_restore_done, Toast.LENGTH_SHORT).show();
}
Expand Down Expand Up @@ -801,7 +801,7 @@ private void setupDeviceStatus() {
}

private boolean isServiceAvailable() {
return XAppLockManager.get().isServiceAvailable();
return XAppLockManager.get().isServiceAvailable(true);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,24 @@ public static XAPMManager get() {
}

public boolean isServiceAvailable() {
return mService != null;
return isServiceAvailable(false);
}

public boolean isServiceAvailable(boolean doubleConfirm) {
boolean isRegistered = mService != null;
if (!isRegistered) {
return false;
}
if (!doubleConfirm) {
return true;
}
try {
String answer = mService.getBuildVersionName();
return answer != null;
} catch (Throwable e) {
// Dead.
}
return false;
}

public void retrieveService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,24 @@ public static XAppLockManager get() {
}

public boolean isServiceAvailable() {
return mService != null;
return isServiceAvailable(false);
}

public boolean isServiceAvailable(boolean doubleConfirm) {
boolean isRegistered = mService != null;
if (!isRegistered) {
return false;
}
if (!doubleConfirm) {
return true;
}
try {
String answer = mService.getBuildVersionName();
return answer != null;
} catch (Throwable e) {
// Dead.
}
return false;
}

private void ensureService() {
Expand Down

0 comments on commit 75aa7ac

Please sign in to comment.