ブラウザを開く処理でパッケージ名にcom.huawei.android.internal を含むアプリを除外する

This commit is contained in:
tateisu 2020-09-27 07:34:18 +09:00
parent 351c495042
commit 926d40fcc0
4 changed files with 12 additions and 11 deletions

View File

@ -61,6 +61,7 @@
<w>hhmm</w> <w>hhmm</w>
<w>hohoemi</w> <w>hohoemi</w>
<w>hostdon</w> <w>hostdon</w>
<w>huawei</w>
<w>idat</w> <w>idat</w>
<w>idempotency</w> <w>idempotency</w>
<w>ietf</w> <w>ietf</w>

View File

@ -1099,7 +1099,7 @@ class ActMain : AsyncActivity(), Column.Callback, View.OnClickListener,
} }
if(resultCode == Activity.RESULT_OK && data != null) { if(resultCode == Activity.RESULT_OK && data != null) {
startAccessTokenUpdate(data) App1.openBrowser(this, data.data)
} else if(resultCode == ActAccountSetting.RESULT_INPUT_ACCESS_TOKEN && data != null) { } else if(resultCode == ActAccountSetting.RESULT_INPUT_ACCESS_TOKEN && data != null) {
val db_id = data.getLongExtra(ActAccountSetting.EXTRA_DB_ID, - 1L) val db_id = data.getLongExtra(ActAccountSetting.EXTRA_DB_ID, - 1L)
checkAccessToken2(db_id) checkAccessToken2(db_id)
@ -1707,10 +1707,6 @@ class ActMain : AsyncActivity(), Column.Callback, View.OnClickListener,
} }
fun startAccessTokenUpdate(data : Intent) {
App1.openBrowser(this, data.data)
}
// ActOAuthCallbackで受け取ったUriを処理する // ActOAuthCallbackで受け取ったUriを処理する
private fun handleIntentUri(uri : Uri) { private fun handleIntentUri(uri : Uri) {

View File

@ -8,6 +8,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper import android.database.sqlite.SQLiteOpenHelper
@ -620,9 +621,14 @@ class App1 : Application() {
val pm = activity.packageManager !! val pm = activity.packageManager !!
val myName = activity.packageName val myName = activity.packageName
val filter : (ResolveInfo)->Boolean ={
it.activityInfo.packageName != myName &&
it.activityInfo.exported &&
-1 == it.activityInfo.packageName.indexOf("com.huawei.android.internal")
}
// resolveActivity がこのアプリ以外のActivityを返すなら、それがベストなんだろう // resolveActivity がこのアプリ以外のActivityを返すなら、それがベストなんだろう
// ただしAndroid M以降はMATCH_DEFAULT_ONLYだと「常時」が設定されてないとnullを返す // ただしAndroid M以降はMATCH_DEFAULT_ONLYだと「常時」が設定されてないとnullを返す
val ri = pm.resolveActivity( val ri = pm.resolveActivity(
intent, intent,
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@ -630,7 +636,7 @@ class App1 : Application() {
} else { } else {
PackageManager.MATCH_DEFAULT_ONLY PackageManager.MATCH_DEFAULT_ONLY
} }
)?.takeIf { it.activityInfo.packageName != myName } )?.takeIf(filter)
if(ri != null) { if(ri != null) {
intent.setClassName(ri.activityInfo.packageName, ri.activityInfo.name) intent.setClassName(ri.activityInfo.packageName, ri.activityInfo.name)
@ -642,7 +648,7 @@ class App1 : Application() {
activity, activity,
intent, intent,
autoSelect = true, autoSelect = true,
filter = { it.activityInfo.packageName != myName } filter = filter
) { ) {
try { try {
intent.component = it.cn() intent.component = it.cn()

View File

@ -57,9 +57,7 @@ object Action_Account {
when(action) { when(action) {
LoginForm.Action.Existing -> if(data is String) { LoginForm.Action.Existing -> if(data is String) {
// ブラウザ用URLが生成された // ブラウザ用URLが生成された
val intent = Intent() App1.openBrowser(activity, data.toUri())
intent.data = data.toUri()
activity.startAccessTokenUpdate(intent)
dialog.dismissSafe() dialog.dismissSafe()
return return
} }