| | | | |
| Offset 1, 17 lines modified | Offset 1, 16 lines modified |
| | |
| 1 | package·com.android.textclassifier.common.intent; | 1 | package·com.android.textclassifier.common.intent; |
| | |
| | 2 | import·androidx.core.app.RemoteActionCompat; |
| 2 | import·android.content.ComponentName; | 3 | import·android.content.ComponentName; |
| 3 | import·com.google.common.base.Objects; | |
| 4 | import·androidx.core.content.ContextCompat; | 4 | import·androidx.core.content.ContextCompat; |
| 5 | import·android.content.pm.ApplicationInfo; | 5 | import·android.content.pm.ApplicationInfo; |
| 6 | import·android.content.pm.ActivityInfo; | 6 | import·android.content.pm.ActivityInfo; |
| 7 | import·android.content.pm.PackageManager; | 7 | import·android.content.pm.PackageManager; |
| 8 | import·androidx.core.app.RemoteActionCompat; | |
| 9 | import·android.content.pm.ResolveInfo; | 8 | import·android.content.pm.ResolveInfo; |
| 10 | import·android.app.PendingIntent; | 9 | import·android.app.PendingIntent; |
| 11 | import·android.content.pm.PackageManager$NameNotFoundException; | 10 | import·android.content.pm.PackageManager$NameNotFoundException; |
| 12 | import·com.android.textclassifier.common.base.TcLog; | 11 | import·com.android.textclassifier.common.base.TcLog; |
| 13 | import·androidx.core.graphics.drawable.IconCompat; | 12 | import·androidx.core.graphics.drawable.IconCompat; |
| 14 | import·android.content.Context; | 13 | import·android.content.Context; |
| 15 | import·com.google.common.base.Preconditions; | 14 | import·com.google.common.base.Preconditions; |
| Offset 60, 44 lines modified | Offset 59, 27 lines modified |
| 60 | ········} | 59 | ········} |
| 61 | ····} | 60 | ····} |
| 62 | ···· | 61 | ···· |
| 63 | ····private·static·PendingIntent·createPendingIntent(final·Context·context,·final·Intent·intent,·final·int·n)·{ | 62 | ····private·static·PendingIntent·createPendingIntent(final·Context·context,·final·Intent·intent,·final·int·n)·{ |
| 64 | ········return·PendingIntent.getActivity(context,·n,·intent,·134217728); | 63 | ········return·PendingIntent.getActivity(context,·n,·intent,·134217728); |
| 65 | ····} | 64 | ····} |
| 66 | ···· | 65 | ···· |
| 67 | ····private·RemoteActionCompat·createRemoteAction(final·Context·context,·final·Intent·intent,·final·IconCompat·iconCompat,·final·boolean·shouldShowIcon,·final·ResolveInfo·resolveInfo,·LabeledIntent$TitleChooser·default_TITLE_CHOOSER)·{ | |
| 68 | ········final·PendingIntent·pendingIntent·=·createPendingIntent(context,·intent,·this.requestCode); | |
| 69 | ········if·(default_TITLE_CHOOSER·==·null)·{ | |
| 70 | ············default_TITLE_CHOOSER·=·LabeledIntent.DEFAULT_TITLE_CHOOSER; | |
| 71 | ········} | |
| 72 | ········CharSequence·charSequence·=·default_TITLE_CHOOSER.chooseTitle(this,·resolveInfo); | |
| 73 | ········if·(TextUtils.isEmpty(charSequence))·{ | |
| 74 | ············TcLog.w("LabeledIntent",·"Custom·titleChooser·return·null,·fallback·to·the·default·titleChooser"); | |
| 75 | ············charSequence·=·LabeledIntent.DEFAULT_TITLE_CHOOSER.chooseTitle(this,·resolveInfo); | |
| 76 | ········} | |
| 77 | ········final·RemoteActionCompat·remoteActionCompat·=·new·RemoteActionCompat(iconCompat,·charSequence,·(CharSequence)this.resolveDescription(resolveInfo,·context.getPackageManager()),·pendingIntent); | |
| 78 | ········remoteActionCompat.setShouldShowIcon(shouldShowIcon); | |
| 79 | ········return·remoteActionCompat; | |
| 80 | ····} | |
| 81 | ···· | |
| 82 | ····private·static·String·getApplicationName(final·ResolveInfo·resolveInfo,·final·PackageManager·packageManager)·{ | 66 | ····private·static·String·getApplicationName(final·ResolveInfo·resolveInfo,·final·PackageManager·packageManager)·{ |
| 83 | ········if·(resolveInfo·!=·null)·{ | 67 | ········final·ActivityInfo·activityInfo·=·resolveInfo.activityInfo; |
| 84 | ············final·ActivityInfo·activityInfo·=·resolveInfo.activityInfo; | 68 | ········if·(activityInfo·==·null)·{ |
| 85 | ············if·(activityInfo·!=·null)·{ | 69 | ············return·null; |
| 86 | ················if·("android".equals(activityInfo.packageName))·{ | |
| 87 | ····················return·null; | |
| 88 | ················} | |
| 89 | ················final·ApplicationInfo·applicationInfo·=·resolveInfo.activityInfo.applicationInfo; | |
| 90 | ················if·(applicationInfo·==·null)·{ | |
| 91 | ····················return·null; | |
| 92 | ················} | |
| 93 | ················return·packageManager.getApplicationLabel(applicationInfo).toString(); | |
| 94 | ············} | |
| 95 | ········} | 70 | ········} |
| 96 | ········return·null; | 71 | ········if·("android".equals(activityInfo.packageName))·{ |
| | 72 | ············return·null; |
| | 73 | ········} |
| | 74 | ········final·ApplicationInfo·applicationInfo·=·resolveInfo.activityInfo.applicationInfo; |
| | 75 | ········if·(applicationInfo·==·null)·{ |
| | 76 | ············return·null; |
| | 77 | ········} |
| | 78 | ········return·packageManager.getApplicationLabel(applicationInfo).toString(); |
| 97 | ····} | 79 | ····} |
| 98 | ···· | 80 | ···· |
| 99 | ····private·static·boolean·hasPermission(final·Context·context,·final·ActivityInfo·activityInfo)·{ | 81 | ····private·static·boolean·hasPermission(final·Context·context,·final·ActivityInfo·activityInfo)·{ |
| 100 | ········final·boolean·exported·=·activityInfo.exported; | 82 | ········final·boolean·exported·=·activityInfo.exported; |
| 101 | ········boolean·b·=·false; | 83 | ········boolean·b·=·false; |
| 102 | ········if·(!exported)·{ | 84 | ········if·(!exported)·{ |
| 103 | ············return·false; | 85 | ············return·false; |
| Offset 109, 45 lines modified | Offset 91, 31 lines modified |
| 109 | ········} | 91 | ········} |
| 110 | ········if·(ContextCompat.checkSelfPermission(context,·permission)·==·0)·{ | 92 | ········if·(ContextCompat.checkSelfPermission(context,·permission)·==·0)·{ |
| 111 | ············b·=·b2; | 93 | ············b·=·b2; |
| 112 | ········} | 94 | ········} |
| 113 | ········return·b; | 95 | ········return·b; |
| 114 | ····} | 96 | ····} |
| 115 | ···· | 97 | ···· |
| 116 | ····private·boolean·isWebIntent()·{ | |
| 117 | ········final·boolean·equals·=·"android.intent.action.VIEW".equals(this.intent.getAction()); | |
| 118 | ········boolean·b·=·false; | |
| 119 | ········if·(!equals)·{ | |
| 120 | ············return·false; | |
| 121 | ········} | |
| 122 | ········final·String·scheme·=·this.intent.getScheme(); | |
| 123 | ········if·(Objects.equal((Object)scheme,·(Object)"http")·||·Objects.equal((Object)scheme,·(Object)"https"))·{ | |
| 124 | ············b·=·true; | |
| 125 | ········} | |
| 126 | ········return·b; | |
| 127 | ····} | |
| 128 | ···· | |
| 129 | ····private·String·resolveDescription(final·ResolveInfo·resolveInfo,·final·PackageManager·packageManager)·{ | 98 | ····private·String·resolveDescription(final·ResolveInfo·resolveInfo,·final·PackageManager·packageManager)·{ |
| 130 | ········if·(!TextUtils.isEmpty((CharSequence)this.descriptionWithAppName))·{ | 99 | ········if·(!TextUtils.isEmpty((CharSequence)this.descriptionWithAppName))·{ |
| 131 | ············final·String·applicationName·=·getApplicationName(resolveInfo,·packageManager); | 100 | ············final·String·applicationName·=·getApplicationName(resolveInfo,·packageManager); |
| 132 | ············if·(!TextUtils.isEmpty((CharSequence)applicationName))·{ | 101 | ············if·(!TextUtils.isEmpty((CharSequence)applicationName))·{ |
| 133 | ················return·String.format(this.descriptionWithAppName,·applicationName); | 102 | ················return·String.format(this.descriptionWithAppName,·applicationName); |
| 134 | ············} | 103 | ············} |
| 135 | ········} | 104 | ········} |
| 136 | ········return·this.description; | 105 | ········return·this.description; |
| 137 | ····} | 106 | ····} |
| 138 | ···· | 107 | ···· |
| 139 | ····public·LabeledIntent$Result·resolve(final·Context·context,·final·LabeledIntent$TitleChooser·labeledIntent$TitleChooser)·{ | 108 | ····public·LabeledIntent$Result·resolve(final·Context·context,·LabeledIntent$TitleChooser·default_TITLE_CHOOSER)·{ |
| 140 | ········final·PackageManager·packageManager·=·context.getPackageManager(); | 109 | ········final·PackageManager·packageManager·=·context.getPackageManager(); |
| 141 | ········final·Intent·intent·=·this.intent; | 110 | ········final·Intent·intent·=·this.intent; |
| 142 | ········boolean·b·=·false; | 111 | ········boolean·shouldShowIcon·=·false; |
| 143 | ········final·ResolveInfo·resolveActivity·=·packageManager.resolveActivity(intent,·0); | 112 | ········final·ResolveInfo·resolveActivity·=·packageManager.resolveActivity(intent,·0); |
| 144 | ········final·int·n·=·17301573; | 113 | ········IconCompat·iconCompat·=·null; |
| 145 | ········final·String·s·=·"LabeledIntent"; | 114 | ········final·String·s·=·"LabeledIntent"; |
| 146 | ········IconCompat·iconFromPackage·=·null; | |
| 147 | ········if·(resolveActivity·!=·null)·{ | 115 | ········if·(resolveActivity·!=·null)·{ |
| 148 | ············final·ActivityInfo·activityInfo·=·resolveActivity.activityInfo; | 116 | ············final·ActivityInfo·activityInfo·=·resolveActivity.activityInfo; |
| 149 | ············if·(activityInfo·!=·null)·{ | 117 | ············if·(activityInfo·!=·null)·{ |
| 150 | ················if·(!hasPermission(context,·activityInfo))·{ | 118 | ················if·(!hasPermission(context,·activityInfo))·{ |
| 151 | ····················final·StringBuilder·sb·=·new·StringBuilder(); | 119 | ····················final·StringBuilder·sb·=·new·StringBuilder(); |
| 152 | ····················sb.append("No·permission·to·access:·"); | 120 | ····················sb.append("No·permission·to·access:·"); |
| 153 | ····················sb.append(resolveActivity.activityInfo); | 121 | ····················sb.append(resolveActivity.activityInfo); |
| Offset 158, 32 lines modified | Offset 126, 35 lines modified |
| 158 | ················final·String·packageName·=·activityInfo2.packageName; | 126 | ················final·String·packageName·=·activityInfo2.packageName; |
| 159 | ················final·String·name·=·activityInfo2.name; | 127 | ················final·String·name·=·activityInfo2.name; |
| 160 | ················if·(packageName·!=·null·&&·name·!=·null)·{ | 128 | ················if·(packageName·!=·null·&&·name·!=·null)·{ |
| 161 | ····················final·Intent·intent2·=·new·Intent(this.intent); | 129 | ····················final·Intent·intent2·=·new·Intent(this.intent); |
| 162 | ····················if·(!"android".equals(packageName))·{ | 130 | ····················if·(!"android".equals(packageName))·{ |
| 163 | ························intent2.setComponent(new·ComponentName(packageName,·name)); | 131 | ························intent2.setComponent(new·ComponentName(packageName,·name)); |
| 164 | ························if·(resolveActivity.activityInfo.getIconResource()·!=·0)·{ | 132 | ························if·(resolveActivity.activityInfo.getIconResource()·!=·0)·{ |
| 165 | ····························iconFromPackage·=·createIconFromPackage(context,·packageName,·resolveActivity.activityInfo.getIconResource()); | 133 | ····························iconCompat·=·createIconFromPackage(context,·packageName,·resolveActivity.activityInfo.getIconResource()); |
| 166 | ····························b·=·true; | 134 | ····························shouldShowIcon·=·true; |
| 167 | ························} | 135 | ························} |
| 168 | ····················} | 136 | ····················} |
| 169 | ····················final·boolean·b2·=·b; | 137 | ····················if·(iconCompat·==·null)·{ |
| 170 | ····················IconCompat·withResource; | 138 | ························iconCompat·=·IconCompat.createWithResource(context,·17301573); |
| 171 | ····················if·(iconFromPackage·==·null)·{ | 139 | ····················} |
| 172 | ························withResource·=·IconCompat.createWithResource(context,·n); | 140 | ····················final·PendingIntent·pendingIntent·=·createPendingIntent(context,·intent2,·this.requestCode); |
| | 141 | ····················if·(default_TITLE_CHOOSER·==·null)·{ |
| | 142 | ························default_TITLE_CHOOSER·=·LabeledIntent.DEFAULT_TITLE_CHOOSER; |
| 173 | ····················} | 143 | ····················} |
| 174 | ····················else·{ | 144 | ····················CharSequence·charSequence·=·default_TITLE_CHOOSER.chooseTitle(this,·resolveActivity); |
| 175 | ························withResource·=·iconFromPackage; | 145 | ····················if·(TextUtils.isEmpty(charSequence))·{ |
| | 146 | ························TcLog.w(s,·"Custom·titleChooser·return·null,·fallback·to·the·default·titleChooser"); |
| | 147 | ························charSequence·=·LabeledIntent.DEFAULT_TITLE_CHOOSER.chooseTitle(this,·resolveActivity); |
| 176 | ····················} | 148 | ····················} |
| 177 | ····················return·new·LabeledIntent$Result(intent2,·this.createRemoteAction(context,·intent2,·withResource,·b2,·resolveActivity,·labeledIntent$TitleChooser)); | 149 | ····················final·RemoteActionCompat·remoteActionCompat·=·new·RemoteActionCompat(iconCompat,·charSequence,·(CharSequence)this.resolveDescription(resolveActivity,·packageManager),·pendingIntent); |
| | 150 | ····················remoteActionCompat.setShouldShowIcon(shouldShowIcon); |
| | 151 | ····················return·new·LabeledIntent$Result(intent2,·remoteActionCompat); |
| 178 | ················} | 152 | ················} |
| 179 | ················TcLog.w(s,·"packageName·or·className·is·null"); | 153 | ················TcLog.w(s,·"packageName·or·className·is·null"); |
| 180 | ················return·null; | 154 | ················return·null; |
| 181 | ············} | 155 | ············} |
| 182 | ········} | 156 | ········} |
| 183 | ········if·(this.isWebIntent())·{ | |
| 184 | ············return·new·LabeledIntent$Result(new·Intent(this.intent),·this.createRemoteAction(context,·this.intent,·IconCompat.createWithResource(context,·n),·false,·resolveActivity,·labeledIntent$TitleChooser)); | |
| 185 | ········} | |
| 186 | ········TcLog.w(s,·"resolveInfo·or·activityInfo·is·null"); | 157 | ········TcLog.w(s,·"resolveInfo·or·activityInfo·is·null"); |
| 187 | ········return·null; | 158 | ········return·null; |
| 188 | ····} | 159 | ····} |
| 189 | } | 160 | } |