diff --git a/app/src/main/java/acr/browser/lightning/IncognitoActivity.kt b/app/src/main/java/acr/browser/lightning/IncognitoActivity.kt index 7550a4799..459135a2e 100644 --- a/app/src/main/java/acr/browser/lightning/IncognitoActivity.kt +++ b/app/src/main/java/acr/browser/lightning/IncognitoActivity.kt @@ -4,9 +4,9 @@ import acr.browser.lightning.browser.activity.BrowserActivity import android.content.Context import android.content.Intent import android.net.Uri -import android.os.Build +import android.os.Bundle +import android.view.WindowManager import android.webkit.CookieManager -import android.webkit.CookieSyncManager import dagger.hilt.android.AndroidEntryPoint import io.reactivex.Completable import javax.inject.Inject @@ -18,12 +18,11 @@ class IncognitoActivity @Inject constructor(): BrowserActivity() { override fun provideAccentThemeOverride(): AccentTheme = AccentTheme.PINK - @Suppress("DEPRECATION") + /** + * + */ public override fun updateCookiePreference(): Completable = Completable.fromAction { val cookieManager = CookieManager.getInstance() - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - CookieSyncManager.createInstance(this@IncognitoActivity) - } if (Capabilities.FULL_INCOGNITO.isSupported) { cookieManager.setAcceptCookie(userPreferences.cookiesEnabled) } else { @@ -31,12 +30,22 @@ class IncognitoActivity @Inject constructor(): BrowserActivity() { } } - @Suppress("RedundantOverride") + /** + * + */ override fun onNewIntent(intent: Intent) { handleNewIntent(intent) super.onNewIntent(intent) } + /** + * + */ + override fun onCreate(savedInstanceState: Bundle?) { + window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + super.onCreate(savedInstanceState) + } + @Suppress("RedundantOverride") override fun onPause() = super.onPause() // saveOpenTabs(); diff --git a/app/src/main/java/acr/browser/lightning/browser/activity/BrowserActivity.kt b/app/src/main/java/acr/browser/lightning/browser/activity/BrowserActivity.kt index 134beb39a..29d3796c5 100644 --- a/app/src/main/java/acr/browser/lightning/browser/activity/BrowserActivity.kt +++ b/app/src/main/java/acr/browser/lightning/browser/activity/BrowserActivity.kt @@ -268,6 +268,7 @@ abstract class BrowserActivity : ThemedBrowserActivity(), BrowserView, UIControl protected abstract fun updateCookiePreference(): Completable override fun onCreate(savedInstanceState: Bundle?) { + Timber.v("onCreate") // Need to go first to inject our components super.onCreate(savedInstanceState) diff --git a/app/src/main/java/acr/browser/lightning/utils/MemoryLeakUtils.java b/app/src/main/java/acr/browser/lightning/utils/MemoryLeakUtils.java index 0e704e467..dd7f65684 100644 --- a/app/src/main/java/acr/browser/lightning/utils/MemoryLeakUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/MemoryLeakUtils.java @@ -70,31 +70,8 @@ public static void clearNextServedView(@NonNull Activity activity, @NonNull Appl Log.d(TAG, "Unable to invoke method in clearNextServedView", e); } } - } - public static abstract class LifecycleAdapter implements Application.ActivityLifecycleCallbacks { - @Override - public void onActivityCreated(Activity activity, Bundle savedInstanceState) {} - - @Override - public void onActivityStarted(Activity activity) {} - - @Override - public void onActivityResumed(Activity activity) {} - - @Override - public void onActivityPaused(Activity activity) {} - - @Override - public void onActivityStopped(Activity activity) {} - - @Override - public void onActivitySaveInstanceState(Activity activity, Bundle outState) {} - - @Override - public void onActivityDestroyed(Activity activity) {} - } } diff --git a/app/src/main/java/fulguris/App.kt b/app/src/main/java/fulguris/App.kt index d93c04d9c..43c9301bf 100644 --- a/app/src/main/java/fulguris/App.kt +++ b/app/src/main/java/fulguris/App.kt @@ -23,6 +23,7 @@ package fulguris import acr.browser.lightning.BuildConfig +import acr.browser.lightning.IncognitoActivity import acr.browser.lightning.R import acr.browser.lightning.database.bookmark.BookmarkExporter import acr.browser.lightning.database.bookmark.BookmarkRepository @@ -43,7 +44,6 @@ import android.content.SharedPreferences import android.os.Build import android.os.Bundle import android.webkit.WebView -import androidx.appcompat.app.AppCompatDelegate import com.jakewharton.threetenabp.AndroidThreeTen import dagger.hilt.android.HiltAndroidApp import io.reactivex.Scheduler @@ -52,11 +52,13 @@ import timber.log.Timber import javax.inject.Inject import kotlin.system.exitProcess + @SuppressLint("StaticFieldLeak") lateinit var app: App @HiltAndroidApp -class App : Application(), SharedPreferences.OnSharedPreferenceChangeListener { +class App : Application(), SharedPreferences.OnSharedPreferenceChangeListener, + Application.ActivityLifecycleCallbacks { @Inject internal lateinit var developerPreferences: DeveloperPreferences @Inject internal lateinit var userPreferences: UserPreferences @@ -71,6 +73,19 @@ class App : Application(), SharedPreferences.OnSharedPreferenceChangeListener { //Ugly way to pass our domain around for settings var domain: String = "" + /** + * Our app can runs in a different process when using the incognito activity. + * This tells us which process it is. + * However this is initialized after the activity creation when running on versions before Android 9. + */ + var incognito = false + private set(value) { + if (value) { + Timber.d("Incognito app process") + } + field = value + } + override fun attachBaseContext(base: Context) { super.attachBaseContext(base) // We only need to install that multi DEX library when not doing minify code optimization, typically in debug, and on devices below API level 21. @@ -108,8 +123,50 @@ class App : Application(), SharedPreferences.OnSharedPreferenceChangeListener { } + override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { + Timber.v("onActivityCreated") + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { + if (activity is IncognitoActivity) { + // Needed as the process check we use below does not work before Android 9 + incognito = true + } + } + } + + override fun onActivityStarted(activity: Activity) { + Timber.v("onActivityStarted") + } + + override fun onActivityResumed(activity: Activity) { + Timber.v("onActivityResumed") + resumedActivity = activity + } + + override fun onActivityPaused(activity: Activity) { + Timber.v("onActivityPaused") + resumedActivity = null + } + + override fun onActivityStopped(activity: Activity) { + Timber.v("onActivityStopped") + } + + override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) { + Timber.v("onActivitySaveInstanceState") + } + + override fun onActivityDestroyed(activity: Activity) { + Timber.v("onActivityDestroyed") + MemoryLeakUtils.clearNextServedView(activity, this@App) + } + + + /** + * + */ override fun onCreate() { app = this + registerActivityLifecycleCallbacks(this) // SL: Use this to debug when launched from another app for instance //Debug.waitForDebugger() super.onCreate() @@ -117,6 +174,7 @@ class App : Application(), SharedPreferences.OnSharedPreferenceChangeListener { userPreferences.preferences.registerOnSharedPreferenceChangeListener(this) plantTimberLogs() + Timber.v("onCreate") AndroidThreeTen.init(this); @@ -133,8 +191,9 @@ class App : Application(), SharedPreferences.OnSharedPreferenceChangeListener { */ } - if (Build.VERSION.SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (getProcessName() == "$packageName:incognito") { + incognito = true WebView.setDataDirectorySuffix("incognito") } } @@ -177,28 +236,6 @@ class App : Application(), SharedPreferences.OnSharedPreferenceChangeListener { WebView.setWebContentsDebuggingEnabled(true) } - registerActivityLifecycleCallbacks(object : MemoryLeakUtils.LifecycleAdapter() { - override fun onActivityDestroyed(activity: Activity) { - Timber.d("onActivityDestroyed") - MemoryLeakUtils.clearNextServedView(activity, this@App) - } - - override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { - Timber.d("onActivityCreated") - } - - // Track current activity - override fun onActivityResumed(activity: Activity) { - Timber.d("onActivityResumed") - resumedActivity = activity - } - - // Track current activity - override fun onActivityPaused(activity: Activity) { - Timber.d("onActivityPaused") - resumedActivity = null - } - }) } @@ -208,20 +245,14 @@ class App : Application(), SharedPreferences.OnSharedPreferenceChangeListener { // Apparently we take care of not leaking it above @SuppressLint("StaticFieldLeak") var resumedActivity: Activity? = null + private set /** * Used to get current activity context in order to access current theme. */ fun currentContext() : Context { - val act = resumedActivity - if (act!=null) - { - return act - } - else - { - return app - } + return resumedActivity + ?: app } /** @@ -232,9 +263,6 @@ class App : Application(), SharedPreferences.OnSharedPreferenceChangeListener { LocaleUtils.updateLocale(app, requestLocale) } - init { - AppCompatDelegate.setCompatVectorFromResourcesEnabled(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) - } } /**