Loading app/src/main/AndroidManifest.xml +11 −0 Original line number Diff line number Diff line Loading @@ -111,5 +111,16 @@ http://www.gnu.org/licenses/gpl.html <!--.....--> <receiver android:name=".receivers.ConnectivityReceiver" android:enabled="true"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <action android:name="android.net.wifi.WIFI_STATE_CHANGED"/> <action android:name="android.net.wifi.STATE_CHANGE"/> </intent-filter> </receiver> </application> </manifest> app/src/main/java/foundation/e/drive/receivers/ConnectivityReceiver.java 0 → 100644 +53 −0 Original line number Diff line number Diff line package foundation.e.drive.receivers; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; import java.io.IOException; public class ConnectivityReceiver extends BroadcastReceiver { public static ConnectivityReceiverListener connectivityReceiverListener; public ConnectivityReceiver() { super(); } public boolean isConnected(Context context) { // String command = "ping -c 1 google.com"; // return (Runtime.getRuntime().exec(command).waitFor() == 0); try { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); //should check null because in airplane mode it will be null return (netInfo != null && netInfo.isConnected()); } catch (NullPointerException e) { e.printStackTrace(); return false; } } @Override public void onReceive(Context context, Intent arg1) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); //if (connectivityReceiverListener != null) { Log.e("TAG", "ConnectivityReceiver onNetworkConnectionChanged...." + isConnected); //connectivityReceiverListener.onNetworkConnectionChanged(isConnected); //} } public interface ConnectivityReceiverListener { void onNetworkConnectionChanged(boolean isConnected); } } No newline at end of file app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java +2 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ public class ScreenOffReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "onReceive"); // i will use this code for check file sync list /*String intentAction = intent.getAction(); if(intentAction == null){ Log.e(TAG, "intent Action is null"); Loading app/src/main/java/foundation/e/drive/services/InitializerService.java +29 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.os.Build; import android.os.Environment; import android.os.Handler; Loading @@ -33,6 +34,7 @@ import java.util.List; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; import foundation.e.drive.receivers.ConnectivityReceiver; import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; Loading @@ -47,7 +49,8 @@ import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNCABLE_CATEGORIES /** * @author Vincent Bourgmayer */ public class InitializerService extends Service implements OnRemoteOperationListener { public class InitializerService extends Service implements OnRemoteOperationListener, ConnectivityReceiver.ConnectivityReceiverListener { final private String TAG = InitializerService.class.getSimpleName(); //Complex properties private int existingRemoteFolderCounter; //@dev-only; Temporarily used to know if all remotePath exist Loading @@ -56,6 +59,7 @@ public class InitializerService extends Service implements OnRemoteOperationList private Handler mHandler; private Account mAccount; private int restartFolderCreationCounter =0; private ConnectivityReceiver connectivityReceiver; @Override public void onCreate() { Loading @@ -63,8 +67,16 @@ public class InitializerService extends Service implements OnRemoteOperationList super.onCreate(); this.existingRemoteFolderCounter = 0; //JobUtils.scheduleInitializerJob(getApplicationContext()); connectivityReceiver = new ConnectivityReceiver(); registerNetworkBroadcastForNougat(); } private void registerNetworkBroadcastForNougat() { registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } @Override public int onStartCommand( Intent intent, int flags, int startId ) { Log.i(TAG, "onStartCommand(...)"); Loading Loading @@ -311,6 +323,14 @@ public class InitializerService extends Service implements OnRemoteOperationList this.mCloudClient = null; if(this.mSyncedFolders != null) this.mSyncedFolders.clear(); this.mSyncedFolders = null; unregisterNetworkChanges(); } protected void unregisterNetworkChanges() { try { unregisterReceiver(connectivityReceiver); } catch (IllegalArgumentException e) { e.printStackTrace(); } } @Nullable Loading @@ -318,4 +338,12 @@ public class InitializerService extends Service implements OnRemoteOperationList public IBinder onBind(Intent intent) { return null; } @Override public void onNetworkConnectionChanged(boolean isConnected) { //just for testing code for now Log.e("TAG", "onNetworkConnectionChanged...." + isConnected); } } No newline at end of file Loading
app/src/main/AndroidManifest.xml +11 −0 Original line number Diff line number Diff line Loading @@ -111,5 +111,16 @@ http://www.gnu.org/licenses/gpl.html <!--.....--> <receiver android:name=".receivers.ConnectivityReceiver" android:enabled="true"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <action android:name="android.net.wifi.WIFI_STATE_CHANGED"/> <action android:name="android.net.wifi.STATE_CHANGE"/> </intent-filter> </receiver> </application> </manifest>
app/src/main/java/foundation/e/drive/receivers/ConnectivityReceiver.java 0 → 100644 +53 −0 Original line number Diff line number Diff line package foundation.e.drive.receivers; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; import java.io.IOException; public class ConnectivityReceiver extends BroadcastReceiver { public static ConnectivityReceiverListener connectivityReceiverListener; public ConnectivityReceiver() { super(); } public boolean isConnected(Context context) { // String command = "ping -c 1 google.com"; // return (Runtime.getRuntime().exec(command).waitFor() == 0); try { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); //should check null because in airplane mode it will be null return (netInfo != null && netInfo.isConnected()); } catch (NullPointerException e) { e.printStackTrace(); return false; } } @Override public void onReceive(Context context, Intent arg1) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); //if (connectivityReceiverListener != null) { Log.e("TAG", "ConnectivityReceiver onNetworkConnectionChanged...." + isConnected); //connectivityReceiverListener.onNetworkConnectionChanged(isConnected); //} } public interface ConnectivityReceiverListener { void onNetworkConnectionChanged(boolean isConnected); } } No newline at end of file
app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java +2 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ public class ScreenOffReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "onReceive"); // i will use this code for check file sync list /*String intentAction = intent.getAction(); if(intentAction == null){ Log.e(TAG, "intent Action is null"); Loading
app/src/main/java/foundation/e/drive/services/InitializerService.java +29 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.os.Build; import android.os.Environment; import android.os.Handler; Loading @@ -33,6 +34,7 @@ import java.util.List; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; import foundation.e.drive.receivers.ConnectivityReceiver; import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; Loading @@ -47,7 +49,8 @@ import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNCABLE_CATEGORIES /** * @author Vincent Bourgmayer */ public class InitializerService extends Service implements OnRemoteOperationListener { public class InitializerService extends Service implements OnRemoteOperationListener, ConnectivityReceiver.ConnectivityReceiverListener { final private String TAG = InitializerService.class.getSimpleName(); //Complex properties private int existingRemoteFolderCounter; //@dev-only; Temporarily used to know if all remotePath exist Loading @@ -56,6 +59,7 @@ public class InitializerService extends Service implements OnRemoteOperationList private Handler mHandler; private Account mAccount; private int restartFolderCreationCounter =0; private ConnectivityReceiver connectivityReceiver; @Override public void onCreate() { Loading @@ -63,8 +67,16 @@ public class InitializerService extends Service implements OnRemoteOperationList super.onCreate(); this.existingRemoteFolderCounter = 0; //JobUtils.scheduleInitializerJob(getApplicationContext()); connectivityReceiver = new ConnectivityReceiver(); registerNetworkBroadcastForNougat(); } private void registerNetworkBroadcastForNougat() { registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } @Override public int onStartCommand( Intent intent, int flags, int startId ) { Log.i(TAG, "onStartCommand(...)"); Loading Loading @@ -311,6 +323,14 @@ public class InitializerService extends Service implements OnRemoteOperationList this.mCloudClient = null; if(this.mSyncedFolders != null) this.mSyncedFolders.clear(); this.mSyncedFolders = null; unregisterNetworkChanges(); } protected void unregisterNetworkChanges() { try { unregisterReceiver(connectivityReceiver); } catch (IllegalArgumentException e) { e.printStackTrace(); } } @Nullable Loading @@ -318,4 +338,12 @@ public class InitializerService extends Service implements OnRemoteOperationList public IBinder onBind(Intent intent) { return null; } @Override public void onNetworkConnectionChanged(boolean isConnected) { //just for testing code for now Log.e("TAG", "onNetworkConnectionChanged...." + isConnected); } } No newline at end of file