Przeglądaj źródła

Resolved 2 crashes of IndexOutOfBoundsException on server list screen and firebase email custom NullPointerException and currently removed code for open wifi network detection

Khubaib 3 miesięcy temu
rodzic
commit
89cc0d1d3b

+ 20 - 20
app/src/main/AndroidManifest.xml

@@ -14,10 +14,10 @@
 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.INTERNET" />
-    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
-    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
-    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
-    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+<!--    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />-->
+<!--    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />-->
+<!--    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />-->
+<!--    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />-->
     <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
     <uses-permission android:name="com.android.vending.BILLING" />
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
@@ -204,22 +204,22 @@
                 android:value="true" />
         </service>
 
-        <receiver
-            android:name=".utils.WifiScanReceiver"
-            android:enabled="true"
-            android:exported="true">
-            <intent-filter>
-                <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
-                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
-                <action android:name="android.net.wifi.STATE_CHANGE" />
-                <action android:name="android.net.wifi.SCAN_RESULTS" />
-                <action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />
-            </intent-filter>
-        </receiver>
-
-        <service
-            android:name=".fcm.NetworkJobService"
-            android:permission="android.permission.BIND_JOB_SERVICE" />
+<!--        <receiver-->
+<!--            android:name=".utils.WifiScanReceiver"-->
+<!--            android:enabled="true"-->
+<!--            android:exported="true">-->
+<!--            <intent-filter>-->
+<!--                <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />-->
+<!--                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />-->
+<!--                <action android:name="android.net.wifi.STATE_CHANGE" />-->
+<!--                <action android:name="android.net.wifi.SCAN_RESULTS" />-->
+<!--                <action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />-->
+<!--            </intent-filter>-->
+<!--        </receiver>-->
+
+<!--        <service-->
+<!--            android:name=".fcm.NetworkJobService"-->
+<!--            android:permission="android.permission.BIND_JOB_SERVICE" />-->
 
     </application>
 

+ 16 - 6
app/src/main/java/com/vpn/fastestvpnservice/MainActivity.kt

@@ -15,7 +15,6 @@ import android.view.WindowInsets
 import android.view.WindowInsetsController
 import android.view.WindowManager
 import androidx.activity.compose.setContent
-import androidx.annotation.RequiresApi
 import androidx.compose.foundation.isSystemInDarkTheme
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
@@ -28,6 +27,7 @@ import androidx.core.content.ContextCompat
 import androidx.core.view.WindowCompat
 import androidx.fragment.app.FragmentManager
 import androidx.navigation.compose.rememberNavController
+import com.google.firebase.crashlytics.FirebaseCrashlytics
 import com.vpn.fastestvpnservice.activities.DockActivity
 import com.vpn.fastestvpnservice.activities.SplashActivity2
 import com.vpn.fastestvpnservice.beans.isDarkTheme
@@ -104,12 +104,22 @@ open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityRecei
 
         WindowCompat.setDecorFitsSystemWindows(window, false)
 
-        wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
-        wifiScanReceiver = WifiScanReceiver()
-        intentFilter = IntentFilter()
-        intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION)
+//        wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
+//        wifiScanReceiver = WifiScanReceiver()
+//        intentFilter = IntentFilter()
+//        intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION)
+//
+//        ContextCompat.registerReceiver(applicationContext, wifiScanReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED)
+
+        val isLoggedIn = basePreferenceHelper.getLoggedInState()
 
-        ContextCompat.registerReceiver(applicationContext, wifiScanReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED)
+        if (isLoggedIn) {
+            val email = basePreferenceHelper.getUser()?.userinfo?.email
+            if (email != null) {
+                FirebaseCrashlytics.getInstance().setUserId(email)
+                FirebaseCrashlytics.getInstance().setCustomKey("email", email)
+            }
+        }
 
         setContent {
             val context = LocalContext.current

+ 15 - 11
app/src/main/java/com/vpn/fastestvpnservice/screens/ServerListScreen.kt

@@ -632,32 +632,36 @@ fun ColumnScope.ShowAllLocationsList(
             LocalOverscrollConfiguration provides null
         ) {
             Column(modifier = Modifier.fillMaxSize()) {
-//                Log.d("serverTabPager = ", "serverTabPager: ${serverTabPager} , selectedTabIndex: $selectedTabIndex")
                 CompositionLocalProvider(
                     LocalOverscrollConfiguration provides null
                 )
                 {
-                    var pingResult: Int = 0
-//                    Log.d("filterServersList", "filterServersList: ${filterServersList.size}")
-
                     val countries = serverListViewModelSplash.liveDataGetServersGlobal.observeAsState().value
                     val groupServers = serverListViewModelSplash.liveDataGroupServers.observeAsState().value
                     var countriesFilter = ArrayList<ServerDataGlobal?>()
 
                     if (isAlphabetList.value) {
-                        countriesFilter = serversListFinalGlobal as ArrayList
-                        countriesFilter.get(selectedTabIndex)?.servers?.sortBy {
-                            if (selectedTabIndex == 0) it.country else it.server_name
-                        }
-                        groupServers?.sortBy {
-                            it?.name
+//                        countriesFilter = serversListFinalGlobal as ArrayList
+                        if (countries != null) {
+                            countriesFilter = countries
                         }
 
-                        serverListViewModelSplash.mutableLiveDataGroupServers.value = groupServers
+                        if (countriesFilter.size != 0) {
+                            countriesFilter.get(selectedTabIndex)?.servers?.sortBy {
+                                if (selectedTabIndex == 0) it.country else it.server_name
+                            }
+                            groupServers?.sortBy {
+                                it?.name
+                            }
+
+                            serverListViewModelSplash.mutableLiveDataGroupServers.value = groupServers
+                        }
                     }
                     else {
                         if (countries != null) {
                             countriesFilter = countries
+                        }
+                        if (countriesFilter.size != 0) {
                             countriesFilter.get(selectedTabIndex)?.servers?.let {
                                 if (selectedTabIndex == 0) {
                                     it.sortBy {server ->

+ 0 - 11
app/src/main/java/de/blinkt/openvpn/core/App.java

@@ -161,17 +161,6 @@ public class App extends /*com.orm.SugarApp*/ Application {
         FirebaseApp.initializeApp(this);
         FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
 
-        BasePreferenceHelper basePreferenceHelper = new BasePreferenceHelper(getApplicationContext());
-        boolean isLoggedIn = basePreferenceHelper.getLoggedInState();
-
-        if (isLoggedIn) {
-            String email = Objects.requireNonNull(Objects.requireNonNull(basePreferenceHelper.getUser()).getUserinfo()).getEmail();
-            if (email != null) {
-                FirebaseCrashlytics.getInstance().setUserId(email);
-                FirebaseCrashlytics.getInstance().setCustomKey("email", email);
-            }
-        }
-
         /*SharedPreferences sp_settings = getSharedPreferences("settings_data", 0);
         device_id = sp_settings.getString("device_id", "NULL");