Skip to content

Commit

Permalink
修复在 MIUI Android 11 ~ 12 中 绑定或换绑手机号页面闪退
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed May 10, 2022
1 parent c46e3bb commit 13a6cf0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,6 @@ dotnet_diagnostic.SA1303.severity = silent

# SA1300: Element should begin with upper-case letter
dotnet_diagnostic.SA1300.severity = silent

# SA1316: Tuple element names should use correct casing
dotnet_diagnostic.SA1316.severity = silent
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ public PlatformTelephonyServiceImpl(IPermissions p) : base(p)
{
}

protected override string? PlatformGetPhoneNumber()
TelephonyManager? telephonyManager;

public TelephonyManager TelephonyManager
{
try
{
var telephony = XEPlatform.AppContext.GetSystemService<TelephonyManager>(Context.TelephonyService);
var value = telephony.Line1Number;
return PhoneNumberHelper.GetChineseMainlandPhoneNumber(value);
}
catch
get
{
return null;
if (telephonyManager == null)
telephonyManager = XEPlatform.AppContext.GetSystemService<TelephonyManager>(Context.TelephonyService);
return telephonyManager;
}
}

protected override string? PlatformGetPhoneNumber()
{
var value = TelephonyManager.Line1Number;
return PhoneNumberHelper.GetChineseMainlandPhoneNumber(value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,46 @@ public TelephonyServiceImpl(IPermissions p)
var status = await p.CheckAndRequestAsync(IPermissions.IGetPhoneNumber.Instance);
if (status.IsOk())
{
return PlatformGetPhoneNumber();
try
{
return PlatformGetPhoneNumber();
}
catch
{
// Xamarin Exception Stack:
// Java.Lang.SecurityException: getLine1NumberForDisplay: Neither user 10837 nor current process has android.permission.READ_PHONE_STATE, android.permission.READ_SMS, or android.permission.READ_PHONE_NUMBERS
// at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <1921523bc22e407fa9a0855bdae29335>:0
// at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <1921523bc22e407fa9a0855bdae29335>:0
// at Android.Telephony.TelephonyManager.get_Line1Number () [0x0000a] in <1f18ef20dc7d4d4196739d809db4caa6>:0
// at System.Application.Services.Implementation.PlatformTelephonyServiceImpl.PlatformGetPhoneNumber () [0x0000f] in <4b916d7fba474bbcb7162327ea0cdf4b>:0
// at System.Application.Services.Implementation.TelephonyServiceImpl.PlatformGetPhoneNumberAsync () [0x0007a] in <3072bb714ec4478ab736cfcc1a194a49>:0
// at System.Application.Services.Implementation.TelephonyServiceImpl.GetPhoneNumberAsync () [0x00062] in <3072bb714ec4478ab736cfcc1a194a49>:0
// at System.Application.Services.ITelephonyService.GetAutoFillPhoneNumberAsync (System.String textBoxText) [0x00062] in <3072bb714ec4478ab736cfcc1a194a49>:0
// ------------------------------------------------------------------------------------------------------------------------------------------
// at System.Application.UI.Fragments.BindPhoneNumberFragment.OnCreateViewAsync () [0x00082] in <4b916d7fba474bbcb7162327ea0cdf4b>:0
// OR
// at System.Application.UI.Fragments.ChangePhoneNumberFragment.OnCreateViewAsync () [0x00068] in <4b916d7fba474bbcb7162327ea0cdf4b>:0
// ------------------------------------------------------------------------------------------------------------------------------------------
// at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <ac5dda0190f24d829c27844a2bccc1dd>:0
// at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <1f18ef20dc7d4d4196739d809db4caa6>:0
// at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <1f18ef20dc7d4d4196739d809db4caa6>:0
// at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <1f18ef20dc7d4d4196739d809db4caa6>:0
// at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.41(intptr,intptr)
// at java.lang.SecurityException: getLine1NumberForDisplay: Neither user 10837 nor current process has android.permission.READ_PHONE_STATE, android.permission.READ_SMS, or android.permission.READ_PHONE_NUMBERS
// at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
// at android.os.Parcel.createException(Parcel.java:2409)
// at android.os.Parcel.readException(Parcel.java:2392)
// at android.os.Parcel.readException(Parcel.java:2334)
// at com.android.internal.telephony.ITelephony$Stub$Proxy.getLine1NumberForDisplay(ITelephony.java:11405)
// at android.telephony.TelephonyManager.getLine1Number(TelephonyManager.java:4755)
// at android.telephony.TelephonyManager.getLine1Number(TelephonyManager.java:4723)
// at crc643a5e764dec9ff28a.BaseFragment_2.n_onCreateView(Native Method)
// https://appcenter.ms/orgs/BeyondDimension/apps/Pro-Steam-1/crashes/errors/1522287042u/overview
// Reports MIUI Android 11 ~ 12
// https://developer.android.google.cn/about/versions/11/privacy/permissions#phone-numbers
// class System.Application.Services.Implementation.Permissions.GetPhoneNumberPermission
// Properties\Permissions.cs
}
}
return null;
}
Expand Down

0 comments on commit 13a6cf0

Please sign in to comment.