1

下面的方法enableHotspot适用于开放网络,但如果我使用那些未注释的配置设置 WPA2 网络,wifi 网络共享保持开启大约 10 秒,并且不执行任何其他操作或触摸屏幕,操作系统崩溃并且我得到黑屏. 3 秒后,它会返回禁用 wifi 网络共享并关闭应用程序。

如果我在 Galaxy Tab 7" 或中文设备上运行相同的进程,设备会自行重启。

这是上面提到的方法:

public static void enableHotspot(String networkSSID,String networkPass, Context context){
    // Enable tethering
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = networkSSID;

    //WPA2
    config.hiddenSSID = true;
    config.preSharedKey = quoteNonHex(networkPass, 64);
    config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
    config.allowedProtocols.set(WifiConfiguration.Protocol.RSN); // For WPA2
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); //this needs a server radius
    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);

    //Simpler WPA2
    //config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
    //config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    //config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);

    //OPEN
    //config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

    WifiApManager wapm = new WifiApManager(context);
    wapm.setWifiApEnabled(config, true);

    Log.d("","Wifi Tethering is enabled.");

}



private static String quoteNonHex(String value, int... allowedLengths) {
    return isHexOfLength(value, allowedLengths) ? value : convertToQuotedString(value);
}

private static boolean isHexOfLength(CharSequence value, int... allowedLengths) {
    if (value == null || !HEX_DIGITS.matcher(value).matches()) {
        return false;
    }
    if (allowedLengths.length == 0) {
        return true;
    }
    for (int length : allowedLengths) {
        if (value.length() == length) {
            return true;
        }
    }
    return false;
}

更新 1

这是按我的应用程序名称过滤的日志,并且Clicked on Card Button正是enableHotspot开始执行的点:

                04-25 16:43:10.610: I/SalesTest.activity.SalesCheckout(12526): Clicked on Card Button
            04-25 16:43:10.710: D/(12526): Wifi Tethering is enabled.
            04-25 16:43:10.840: D/dalvikvm(12526): GC_CONCURRENT freed 1709K, 35% free 32659K/49991K, paused 1ms+3ms
            04-25 16:43:34.805: I/ActivityThread(12526): Removing dead content provider: settings
            04-25 16:43:36.060: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8
            04-25 16:43:36.060: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8
            04-25 16:43:36.060: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8
            04-25 16:43:36.060: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8
            04-25 16:43:36.060: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8
            04-25 16:43:36.065: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8
            04-25 16:43:36.065: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8
            04-25 16:43:36.065: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8
            04-25 16:43:36.065: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8
            04-25 16:43:36.065: E/InputQueue-JNI(12526): channel 'xxxx' ~ Publisher closed input channel or an error occurred.  events=0x8

这是完整的日志,请注意*** FATAL EXCEPTION IN SYSTEM PROCESS

                04-25 16:43:10.610: I/testSalesactivity.SalesCheckout(12526): Clicked on Card Button
            04-25 16:43:10.625: I/power(8588): *** acquire_dvfs_lock : lockType : 1  freq : 1000000 
            04-25 16:43:10.625: I/ActivityManager(8588): START {intent.toShortString} from pid 12526
            04-25 16:43:10.625: D/PowerManagerService(8588): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 1000000  uid : 1000  pid : 8588  tag : ActivityManager
            04-25 16:43:10.625: W/ActivityManager(8588): mDVFSLock.acquire()
            04-25 16:43:10.645: D/ActivityManager(8588): Trying to launch applicationName
            04-25 16:43:10.660: I/SurfaceFlinger(1690): id=161(18) createSurface 0x33e6c (1x1),1 flag=0
            04-25 16:43:10.660: D/PowerManagerService(8588): acquireWakeLock flags=0xa tag=KEEP_SCREEN_ON_FLAG uid=1000 pid=8588   myUID=1000 myPID=8588 myTID=8588
            04-25 16:43:10.705: E/WifiService(8588): Invoking mWifiStateMachine.setWifiEnabled
            04-25 16:43:10.705: D/WifiService(8588): setWifiApEnabled: allowWifiAp: true
            04-25 16:43:10.710: D/(12526): Wifi Tethering is enabled.
            04-25 16:43:10.710: D/WifiP2pService(8588): P2pDisabledState{ what=131203 when=-1ms }
            04-25 16:43:10.720: E/WifiHW(8588): check .ccode.info
            04-25 16:43:10.720: E/WifiHW(8588): /data/.ccode.info already exist!
            04-25 16:43:10.720: E/WifiHW(8588): ====[WIFI]MODULE is semcove=====
            04-25 16:43:10.725: D/com.android.internal.telephony.gsm.FastDormancyStateHelper(8782): onReceive() action=android.net.wifi.WIFI_AP_STATE_CHANGED
            04-25 16:43:10.765: I/SurfaceFlinger(1690): id=162(19) createSurface 0x3ffe4 (800x1280),2 flag=400
            04-25 16:43:10.765: V/PhoneStatusBar(8701): setLightsOn(true)
            04-25 16:43:10.790: I/ClipboardServiceEx(8588): mCBPickerDialog enter case. MSG_DISMISS_DIALOG
            04-25 16:43:10.840: D/dalvikvm(12526): GC_CONCURRENT freed 1709K, 35% free 32659K/49991K, paused 1ms+3ms
            04-25 16:43:10.850: D/DEFERED_APP_VISIBILITY(8588): tweaking closing app
            04-25 16:43:10.855: I/ActivityManager(8588): Displayed shortComponentName: +213ms
            04-25 16:43:11.080: I/SurfaceFlinger(1690): id=160 Removed idx=2 Map Size=5
            04-25 16:43:11.080: I/SurfaceFlinger(1690): id=160 Removed idx=-2 Map Size=5
            04-25 16:43:11.080: I/power(8588): *** release_dvfs_lock : lockType : 1 
            04-25 16:43:11.080: D/PowerManagerService(8588): releaseDVFSLockLocked : all DVFS_MIN_LIMIT are released 
            04-25 16:43:11.080: W/ActivityManager(8588): mDVFSLock.release()
            04-25 16:43:11.840: D/com.android.internal.telephony.gsm.FastDormancyStateHelper(8782): onReceive() action=android.net.conn.TETHER_STATE_CHANGED
            04-25 16:43:11.840: D/Tethering(8588): sendTetherStateChangedBroadcast 1, 0, 0
            04-25 16:43:11.840: E/MTPJNIInterface(10598): tethering status = false
            04-25 16:43:11.855: D/Tethering(8588): InitialState.processMessage what=4
            04-25 16:43:11.860: D/Tethering(8588): sendTetherStateChangedBroadcast 0, 0, 0
            04-25 16:43:11.860: D/com.android.internal.telephony.gsm.FastDormancyStateHelper(8782): onReceive() action=android.net.conn.TETHER_STATE_CHANGED
            04-25 16:43:11.865: E/MTPJNIInterface(10598): tethering status = false
            04-25 16:43:11.870: D/SoftapController(8552): Softap fwReload - Ok
            04-25 16:43:11.870: W/dalvikvm(8588): threadid=83: thread exiting with uncaught exception (group=0x40c721f8)
            04-25 16:43:11.875: E/AndroidRuntime(8588): *** FATAL EXCEPTION IN SYSTEM PROCESS: Thread-127
            04-25 16:43:11.875: E/AndroidRuntime(8588): java.lang.NullPointerException
            04-25 16:43:11.875: E/AndroidRuntime(8588):     at java.nio.charset.ModifiedUtf8.countBytes(ModifiedUtf8.java:75)
            04-25 16:43:11.875: E/AndroidRuntime(8588):     at java.nio.charset.ModifiedUtf8.encode(ModifiedUtf8.java:119)
            04-25 16:43:11.875: E/AndroidRuntime(8588):     at java.io.DataOutputStream.writeUTF(DataOutputStream.java:197)
            04-25 16:43:11.875: E/AndroidRuntime(8588):     at android.net.wifi.WifiApConfigStore.writeApConfiguration(WifiApConfigStore.java:187)
            04-25 16:43:11.875: E/AndroidRuntime(8588):     at android.net.wifi.WifiApConfigStore.access$400(WifiApConfigStore.java:47)
            04-25 16:43:11.875: E/AndroidRuntime(8588):     at android.net.wifi.WifiApConfigStore$ActiveState$1.run(WifiApConfigStore.java:118)
            04-25 16:43:11.875: E/AndroidRuntime(8588):     at java.lang.Thread.run(Thread.java:856)
            04-25 16:43:11.880: E/android.os.Debug(8588): !@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/dumpstate_sys_error
            04-25 16:43:11.905: I/dumpstate(12661): Check if stand-alone
            04-25 16:43:11.920: I/dumpstate(12661): begin
            04-25 16:43:12.045: E/lights(8588): write_int: path /sys/devices/virtual/sec/sec_touchkey/brightness, value 2
            04-25 16:43:12.045: W/PowerManagerService(8588): Timer 0x7->0x3|0x3
            04-25 16:43:12.045: I/PowerManagerService(8588): Ulight 7->3|0
            04-25 16:43:12.045: D/PowerManagerService(8588): setLightBrightness : mButtonLight : 0
            04-25 16:43:12.055: E/DataRouter(1688): usb connection is true 
            04-25 16:43:12.055: E/DataRouter(1688): DSR is ON. Don't send DTR ON.
            04-25 16:43:12.900: D/Tethering(8588): sendTetherStateChangedBroadcast 1, 0, 0

有没有人遇到过类似的问题?关于发生了什么的任何线索?

非常感谢

4

1 回答 1

0

使用反射调用setWifiApConfiguration方法的WifiManager时,ssidWifiConfiguration参数不能为空,否则会导致部分手机系统设置入口,部分手机直接重启,logcat中会看到如下日志:

java.lang.NullPointerException
at java.nio.charset.ModifiedUtf8.countBytes(ModifiedUtf8.java:75)
at java.nio.charset.ModifiedUtf8.encode(ModifiedUtf8.java:119)
at java.io.DataOutputStream.writeUTF(DataOutputStream.java:197)
at android.net.wifi.WifiApConfigStore.writeApConfiguration(WifiApConfigStore.java:207)
at android.net.wifi.WifiApConfigStore.access$400(WifiApConfigStore.java:57)
at android.net.wifi.WifiApConfigStore$ActiveState$1.run(WifiApConfigStore.java:138)
at java.lang.Thread.run(Thread.java:848)
于 2015-08-30T08:17:12.193 回答