This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1810629 - Add an Android shortcut to go straight to the login and…
… passwords
- Loading branch information
1 parent
7ecb339
commit 341fef9
Showing
16 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
fenix/app/src/main/java/org/mozilla/fenix/home/intent/OpenPasswordManagerIntentProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.home.intent | ||
|
||
import android.content.Intent | ||
import androidx.navigation.NavController | ||
import org.mozilla.fenix.HomeActivity | ||
import org.mozilla.fenix.NavGraphDirections | ||
import org.mozilla.fenix.ext.nav | ||
|
||
/** | ||
* When the open password manager shortcut is tapped, Fenix should open to the password and login fragment. | ||
*/ | ||
class OpenPasswordManagerIntentProcessor : HomeIntentProcessor { | ||
|
||
override fun process(intent: Intent, navController: NavController, out: Intent): Boolean { | ||
val event = intent.extras?.getBoolean(HomeActivity.OPEN_PASSWORD_MANAGER) | ||
return if (event != null) { | ||
out.removeExtra(HomeActivity.OPEN_PASSWORD_MANAGER) | ||
|
||
val directions = NavGraphDirections.actionGlobalSavedLoginsAuthFragment() | ||
navController.nav(null, directions) | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
fenix/app/src/main/java/org/mozilla/fenix/shortcut/PasswordManagerIntentProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.shortcut | ||
|
||
import android.content.Intent | ||
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK | ||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK | ||
import mozilla.components.feature.intent.processing.IntentProcessor | ||
import mozilla.components.support.utils.SafeIntent | ||
import org.mozilla.fenix.HomeActivity | ||
|
||
/** | ||
* Intent processor that will handle intents for the password manager shortcut | ||
*/ | ||
class PasswordManagerIntentProcessor : IntentProcessor { | ||
|
||
/** | ||
* Processes the given [Intent]. | ||
* | ||
* @param intent The intent to process. | ||
* @return True if the intent was processed, otherwise false. | ||
*/ | ||
override fun process(intent: Intent): Boolean { | ||
val safeIntent = SafeIntent(intent) | ||
|
||
if (!safeIntent.action.equals(ACTION_OPEN_PASSWORD_MANAGER)) { | ||
return false | ||
} | ||
|
||
intent.putExtra(HomeActivity.OPEN_PASSWORD_MANAGER, true) | ||
intent.flags = intent.flags or FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TASK | ||
return true | ||
} | ||
|
||
companion object { | ||
const val ACTION_OPEN_PASSWORD_MANAGER = "org.mozilla.fenix.OPEN_PASSWORD_MANAGER" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
fenix/app/src/main/res/drawable-v26/ic_static_password_shortcut.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
|
||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<background android:drawable="@color/static_shortcut_background"/> | ||
<foreground android:drawable="@drawable/ic_static_lock"/> | ||
</adaptive-icon> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="48dp" | ||
android:height="48dp" | ||
android:viewportWidth="48" | ||
android:viewportHeight="48"> | ||
<group android:translateX="12" | ||
android:translateY="12"> | ||
<path | ||
android:pathData="M7,11V7C7,4.239 9.239,2 12,2C14.761,2 17,4.239 17,7V11C18.38,11 19.5,12.12 19.5,13.5V19.5C19.5,20.88 18.38,22 17,22H7C5.62,22 4.5,20.88 4.5,19.5V13.5C4.5,12.12 5.62,11 7,11ZM8.75,7C8.75,5.205 10.205,3.75 12,3.75C13.795,3.75 15.25,5.205 15.25,7V11H8.75V7ZM6.25,13.5C6.25,13.086 6.586,12.75 7,12.75H17C17.414,12.75 17.75,13.086 17.75,13.5V19.5C17.75,19.914 17.414,20.25 17,20.25H7C6.586,20.25 6.25,19.914 6.25,19.5V13.5Z" | ||
android:fillColor="#000000" | ||
android:fillType="evenOdd"/> | ||
</group> | ||
</vector> |
9 changes: 9 additions & 0 deletions
9
fenix/app/src/main/res/drawable/ic_static_password_shortcut.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
|
||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:drawable="@drawable/ic_static_shortcut_background" /> | ||
<item android:drawable="@drawable/ic_static_lock" /> | ||
</layer-list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...app/src/test/java/org/mozilla/fenix/home/intent/OpenPasswordManagerIntentProcessorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.home.intent | ||
|
||
import android.content.Intent | ||
import androidx.navigation.NavController | ||
import io.mockk.Called | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mozilla.fenix.HomeActivity | ||
import org.mozilla.fenix.NavGraphDirections | ||
import org.mozilla.fenix.ext.nav | ||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner | ||
import org.mozilla.fenix.shortcut.PasswordManagerIntentProcessor | ||
|
||
@RunWith(FenixRobolectricTestRunner::class) | ||
class OpenPasswordManagerIntentProcessorTest { | ||
|
||
private lateinit var activity: HomeActivity | ||
private lateinit var navController: NavController | ||
private lateinit var out: Intent | ||
private lateinit var processor: OpenPasswordManagerIntentProcessor | ||
|
||
@Before | ||
fun setup() { | ||
activity = mockk(relaxed = true) | ||
navController = mockk(relaxed = true) | ||
out = mockk(relaxed = true) | ||
processor = OpenPasswordManagerIntentProcessor() | ||
} | ||
|
||
@Test | ||
fun `GIVEN a blank intent WHEN it is processed THEN nothing should happen`() { | ||
assertFalse(processor.process(Intent(), navController, out)) | ||
|
||
verify { activity wasNot Called } | ||
verify { navController wasNot Called } | ||
verify { out wasNot Called } | ||
} | ||
|
||
@Test | ||
fun `GIVEN an intent with wrong action WHEN it is processed THEN nothing should happen`() { | ||
val intent = Intent().apply { | ||
action = TEST_WRONG_ACTION | ||
} | ||
|
||
assertFalse(processor.process(intent, navController, out)) | ||
|
||
verify { activity wasNot Called } | ||
verify { navController wasNot Called } | ||
verify { out wasNot Called } | ||
} | ||
|
||
@Test | ||
fun `GIVEN an intent with correct action and extra boolean WHEN it is processed THEN navigate should be called`() { | ||
val intent = Intent().apply { | ||
action = PasswordManagerIntentProcessor.Companion.ACTION_OPEN_PASSWORD_MANAGER | ||
putExtra(HomeActivity.OPEN_PASSWORD_MANAGER, true) | ||
} | ||
|
||
assertTrue(processor.process(intent, navController, out)) | ||
|
||
verify { navController.nav(null, NavGraphDirections.actionGlobalSavedLoginsAuthFragment()) } | ||
verify { out.removeExtra(HomeActivity.OPEN_PASSWORD_MANAGER) } | ||
} | ||
|
||
companion object { | ||
const val TEST_WRONG_ACTION = "test-action" | ||
} | ||
} |