From 45f88c05da847a2ecf970b916e673ccf90af0d51 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 21 Sep 2018 23:06:38 +0200 Subject: [PATCH] remove DeviceActivity and GCM, closes #20 --- AndroidManifest.xml | 14 -- res/layout/device_add_fragment.xml | 53 ---- res/layout/device_link_fragment.xml | 88 ------- res/layout/device_list_fragment.xml | 58 ----- res/layout/device_list_item_view.xml | 33 --- res/xml/preferences.xml | 4 - .../securesms/ApplicationContext.java | 39 +-- .../ApplicationPreferencesActivity.java | 13 - .../securesms/DeviceActivity.java | 236 ------------------ .../securesms/DeviceAddFragment.java | 128 ---------- .../securesms/DeviceLinkFragment.java | 56 ----- .../securesms/DeviceListFragment.java | 217 ---------------- .../securesms/DeviceListItem.java | 62 ----- .../securesms/DeviceProvisioningActivity.java | 42 ---- .../SignalCommunicationModule.java | 5 - .../securesms/jobs/GcmRefreshJob.java | 109 -------- .../preferences/SmsMmsPreferenceFragment.java | 125 ---------- 17 files changed, 1 insertion(+), 1281 deletions(-) delete mode 100644 res/layout/device_add_fragment.xml delete mode 100644 res/layout/device_link_fragment.xml delete mode 100644 res/layout/device_list_fragment.xml delete mode 100644 res/layout/device_list_item_view.xml delete mode 100644 src/org/thoughtcrime/securesms/DeviceActivity.java delete mode 100644 src/org/thoughtcrime/securesms/DeviceAddFragment.java delete mode 100644 src/org/thoughtcrime/securesms/DeviceLinkFragment.java delete mode 100644 src/org/thoughtcrime/securesms/DeviceListFragment.java delete mode 100644 src/org/thoughtcrime/securesms/DeviceListItem.java delete mode 100644 src/org/thoughtcrime/securesms/DeviceProvisioningActivity.java delete mode 100644 src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java delete mode 100644 src/org/thoughtcrime/securesms/preferences/SmsMmsPreferenceFragment.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ffdb87911..128e448b6 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -135,16 +135,6 @@ android:windowSoftInputMode="stateUnchanged" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/> - - - - - - - - - @@ -289,10 +279,6 @@ android:windowSoftInputMode="stateUnchanged" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/> - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/layout/device_link_fragment.xml b/res/layout/device_link_fragment.xml deleted file mode 100644 index e3cdc7672..000000000 --- a/res/layout/device_link_fragment.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/device_list_fragment.xml b/res/layout/device_list_fragment.xml deleted file mode 100644 index 7b73e96b1..000000000 --- a/res/layout/device_list_fragment.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/device_list_item_view.xml b/res/layout/device_list_item_view.xml deleted file mode 100644 index d62de7fbc..000000000 --- a/res/layout/device_list_item_view.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 0ab848f8c..c7f0fc92f 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -21,10 +21,6 @@ android:title="@string/preferences__chats" android:icon="@drawable/ic_forum_24dp"/> - - diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 04e6f9c30..523b24b86 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -39,17 +39,12 @@ import org.thoughtcrime.securesms.jobmanager.dependencies.DependencyInjector; import org.thoughtcrime.securesms.jobmanager.persistence.JavaJobSerializer; import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirementProvider; import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob; -import org.thoughtcrime.securesms.jobs.GcmRefreshJob; import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob; import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirementProvider; import org.thoughtcrime.securesms.jobs.requirements.ServiceRequirementProvider; import org.thoughtcrime.securesms.jobs.requirements.SqlCipherMigrationRequirementProvider; import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess; -import org.thoughtcrime.securesms.service.DirectoryRefreshListener; import org.thoughtcrime.securesms.service.ExpiringMessageManager; -import org.thoughtcrime.securesms.service.LocalBackupListener; -import org.thoughtcrime.securesms.service.RotateSignedPreKeyListener; -import org.thoughtcrime.securesms.service.UpdateApkRefreshListener; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.webrtc.PeerConnectionFactory; import org.webrtc.PeerConnectionFactory.InitializationOptions; @@ -100,10 +95,8 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc initializeDependencyInjection(); initializeJobManager(); initializeExpiringMessageManager(); - //initializeGcmCheck(); -- we're not using google cloud management (aka firebase) - //initializeSignedPreKeyCheck(); -- keys are generated in the core + //initializeSignedPreKeyCheck(); -- keys are generated in the core, however, not sure if this is needed for the lock screen initializePeriodicTasks(); - //initializeCircumvention(); -- this is about countries where signal does not work initializeWebRtc(); ProcessLifecycleOwner.get().getLifecycle().addObserver(this); } @@ -167,16 +160,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc new AxolotlStorageModule(this)); } - private void initializeGcmCheck() { - if (TextSecurePreferences.isPushRegistered(this)) { - long nextSetTime = TextSecurePreferences.getGcmRegistrationIdLastSetTime(this) + TimeUnit.HOURS.toMillis(6); - - if (TextSecurePreferences.getGcmRegistrationId(this) == null || nextSetTime <= System.currentTimeMillis()) { - this.jobManager.add(new GcmRefreshJob(this)); - } - } - } - private void initializeSignedPreKeyCheck() { if (!TextSecurePreferences.isSignedPreKeyRegistered(this)) { jobManager.add(new CreateSignedPreKeyJob(this)); @@ -232,26 +215,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } } - @SuppressLint("StaticFieldLeak") - private void initializeCircumvention() { - AsyncTask task = new AsyncTask() { - @Override - protected Void doInBackground(Void... params) { - if (new SignalServiceNetworkAccess(ApplicationContext.this).isCensored(ApplicationContext.this)) { - try { - ProviderInstaller.installIfNeeded(ApplicationContext.this); - } catch (Throwable t) { - Log.w(TAG, t); - } - } - return null; - } - }; - - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void executePendingContactSync() { if (TextSecurePreferences.needsFullContactSync(this)) { ApplicationContext.getInstance(this).getJobManager().add(new MultiDeviceContactUpdateJob(this, true)); diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index aba06b0d7..9be7d5f66 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -64,7 +64,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA private static final String PREFERENCE_CATEGORY_APP_PROTECTION = "preference_category_app_protection"; private static final String PREFERENCE_CATEGORY_APPEARANCE = "preference_category_appearance"; private static final String PREFERENCE_CATEGORY_CHATS = "preference_category_chats"; - private static final String PREFERENCE_CATEGORY_DEVICES = "preference_category_devices"; private static final String PREFERENCE_CATEGORY_ADVANCED = "preference_category_advanced"; private final DynamicTheme dynamicTheme = new DynamicTheme(); @@ -144,8 +143,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_APPEARANCE)); this.findPreference(PREFERENCE_CATEGORY_CHATS) .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_CHATS)); - this.findPreference(PREFERENCE_CATEGORY_DEVICES) - .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_DEVICES)); this.findPreference(PREFERENCE_CATEGORY_ADVANCED) .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_ADVANCED)); @@ -165,7 +162,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA //noinspection ConstantConditions ((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.text_secure_normal__menu_settings); setCategorySummaries(); - setCategoryVisibility(); } private void setCategorySummaries() { @@ -182,10 +178,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA } private void setCategoryVisibility() { - Preference devicePreference = this.findPreference(PREFERENCE_CATEGORY_DEVICES); - if (devicePreference != null && !TextSecurePreferences.isPushRegistered(getActivity())) { - getPreferenceScreen().removePreference(devicePreference); - } } @TargetApi(11) @@ -215,7 +207,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA this.findPreference(PREFERENCE_CATEGORY_APP_PROTECTION).setIcon(privacy); this.findPreference(PREFERENCE_CATEGORY_APPEARANCE).setIcon(appearance); this.findPreference(PREFERENCE_CATEGORY_CHATS).setIcon(chats); - this.findPreference(PREFERENCE_CATEGORY_DEVICES).setIcon(devices); this.findPreference(PREFERENCE_CATEGORY_ADVANCED).setIcon(advanced); } @@ -243,10 +234,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA case PREFERENCE_CATEGORY_CHATS: fragment = new ChatsPreferenceFragment(); break; - case PREFERENCE_CATEGORY_DEVICES: - Intent intent = new Intent(getActivity(), DeviceActivity.class); - startActivity(intent); - break; case PREFERENCE_CATEGORY_ADVANCED: fragment = new AdvancedPreferenceFragment(); break; diff --git a/src/org/thoughtcrime/securesms/DeviceActivity.java b/src/org/thoughtcrime/securesms/DeviceActivity.java deleted file mode 100644 index 13effaa91..000000000 --- a/src/org/thoughtcrime/securesms/DeviceActivity.java +++ /dev/null @@ -1,236 +0,0 @@ -package org.thoughtcrime.securesms; - -import android.Manifest; -import android.annotation.SuppressLint; -import android.content.Context; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.os.Vibrator; -import android.support.annotation.NonNull; -import android.text.TextUtils; -import android.transition.TransitionInflater; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.Toast; - -import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; -import org.thoughtcrime.securesms.crypto.ProfileKeyUtil; -import org.thoughtcrime.securesms.permissions.Permissions; -import org.thoughtcrime.securesms.push.AccountManagerFactory; -import org.thoughtcrime.securesms.qr.ScanListener; -import org.thoughtcrime.securesms.util.Base64; -import org.thoughtcrime.securesms.util.DynamicLanguage; -import org.thoughtcrime.securesms.util.DynamicTheme; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; -import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask; -import org.whispersystems.libsignal.IdentityKeyPair; -import org.whispersystems.libsignal.InvalidKeyException; -import org.whispersystems.libsignal.ecc.Curve; -import org.whispersystems.libsignal.ecc.ECPublicKey; -import org.whispersystems.libsignal.util.guava.Optional; -import org.whispersystems.signalservice.api.SignalServiceAccountManager; -import org.whispersystems.signalservice.api.push.exceptions.NotFoundException; -import org.whispersystems.signalservice.internal.push.DeviceLimitExceededException; - -import java.io.IOException; - -public class DeviceActivity extends PassphraseRequiredActionBarActivity - implements Button.OnClickListener, ScanListener, DeviceLinkFragment.LinkClickedListener -{ - - private static final String TAG = DeviceActivity.class.getSimpleName(); - - private final DynamicTheme dynamicTheme = new DynamicTheme(); - private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); - - private DeviceAddFragment deviceAddFragment; - private DeviceListFragment deviceListFragment; - private DeviceLinkFragment deviceLinkFragment; - - @Override - public void onPreCreate() { - dynamicTheme.onCreate(this); - dynamicLanguage.onCreate(this); - } - - @Override - public void onCreate(Bundle bundle, boolean ready) { - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setTitle(R.string.AndroidManifest__linked_devices); - this.deviceAddFragment = new DeviceAddFragment(); - this.deviceListFragment = new DeviceListFragment(); - this.deviceLinkFragment = new DeviceLinkFragment(); - - this.deviceListFragment.setAddDeviceButtonListener(this); - this.deviceAddFragment.setScanListener(this); - - if (getIntent().getBooleanExtra("add", false)) { - initFragment(android.R.id.content, deviceAddFragment, dynamicLanguage.getCurrentLocale()); - } else { - initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.getCurrentLocale()); - } - } - - @Override - public void onResume() { - super.onResume(); - dynamicTheme.onResume(this); - dynamicLanguage.onResume(this); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: finish(); return true; - } - - return false; - } - - @Override - public void onClick(View v) { - Permissions.with(this) - .request(Manifest.permission.CAMERA) - .ifNecessary() - .withPermanentDenialDialog(getString(R.string.DeviceActivity_signal_needs_the_camera_permission_in_order_to_scan_a_qr_code)) - .onAllGranted(() -> { - getSupportFragmentManager().beginTransaction() - .replace(android.R.id.content, deviceAddFragment) - .addToBackStack(null) - .commitAllowingStateLoss(); - }) - .onAnyDenied(() -> Toast.makeText(this, R.string.DeviceActivity_unable_to_scan_a_qr_code_without_the_camera_permission, Toast.LENGTH_LONG).show()) - .execute(); - } - - @Override - public void onQrDataFound(final String data) { - Util.runOnMain(() -> { - ((Vibrator)getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50); - Uri uri = Uri.parse(data); - deviceLinkFragment.setLinkClickedListener(uri, DeviceActivity.this); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - deviceAddFragment.setSharedElementReturnTransition(TransitionInflater.from(DeviceActivity.this).inflateTransition(R.transition.fragment_shared)); - deviceAddFragment.setExitTransition(TransitionInflater.from(DeviceActivity.this).inflateTransition(android.R.transition.fade)); - - deviceLinkFragment.setSharedElementEnterTransition(TransitionInflater.from(DeviceActivity.this).inflateTransition(R.transition.fragment_shared)); - deviceLinkFragment.setEnterTransition(TransitionInflater.from(DeviceActivity.this).inflateTransition(android.R.transition.fade)); - - getSupportFragmentManager().beginTransaction() - .addToBackStack(null) - .addSharedElement(deviceAddFragment.getDevicesImage(), "devices") - .replace(android.R.id.content, deviceLinkFragment) - .commit(); - - } else { - getSupportFragmentManager().beginTransaction() - .setCustomAnimations(R.anim.slide_from_bottom, R.anim.slide_to_bottom, - R.anim.slide_from_bottom, R.anim.slide_to_bottom) - .replace(android.R.id.content, deviceLinkFragment) - .addToBackStack(null) - .commit(); - } - }); - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults); - } - - @SuppressLint("StaticFieldLeak") - @Override - public void onLink(final Uri uri) { - new ProgressDialogAsyncTask(this, - R.string.DeviceProvisioningActivity_content_progress_title, - R.string.DeviceProvisioningActivity_content_progress_content) - { - private static final int SUCCESS = 0; - private static final int NO_DEVICE = 1; - private static final int NETWORK_ERROR = 2; - private static final int KEY_ERROR = 3; - private static final int LIMIT_EXCEEDED = 4; - private static final int BAD_CODE = 5; - - @Override - protected Integer doInBackground(Void... params) { - boolean isMultiDevice = TextSecurePreferences.isMultiDevice(DeviceActivity.this); - - try { - Context context = DeviceActivity.this; - SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(context); - String verificationCode = accountManager.getNewDeviceVerificationCode(); - String ephemeralId = uri.getQueryParameter("uuid"); - String publicKeyEncoded = uri.getQueryParameter("pub_key"); - - if (TextUtils.isEmpty(ephemeralId) || TextUtils.isEmpty(publicKeyEncoded)) { - Log.w(TAG, "UUID or Key is empty!"); - return BAD_CODE; - } - - ECPublicKey publicKey = Curve.decodePoint(Base64.decode(publicKeyEncoded), 0); - IdentityKeyPair identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context); - Optional profileKey = Optional.of(ProfileKeyUtil.getProfileKey(getContext())); - - TextSecurePreferences.setMultiDevice(DeviceActivity.this, true); - accountManager.addDevice(ephemeralId, publicKey, identityKeyPair, profileKey, verificationCode); - - return SUCCESS; - } catch (NotFoundException e) { - Log.w(TAG, e); - TextSecurePreferences.setMultiDevice(DeviceActivity.this, isMultiDevice); - return NO_DEVICE; - } catch (DeviceLimitExceededException e) { - Log.w(TAG, e); - TextSecurePreferences.setMultiDevice(DeviceActivity.this, isMultiDevice); - return LIMIT_EXCEEDED; - } catch (IOException e) { - Log.w(TAG, e); - TextSecurePreferences.setMultiDevice(DeviceActivity.this, isMultiDevice); - return NETWORK_ERROR; - } catch (InvalidKeyException e) { - Log.w(TAG, e); - TextSecurePreferences.setMultiDevice(DeviceActivity.this, isMultiDevice); - return KEY_ERROR; - } - } - - @Override - protected void onPostExecute(Integer result) { - super.onPostExecute(result); - - Context context = DeviceActivity.this; - - switch (result) { - case SUCCESS: - Toast.makeText(context, R.string.DeviceProvisioningActivity_content_progress_success, Toast.LENGTH_SHORT).show(); - finish(); - return; - case NO_DEVICE: - Toast.makeText(context, R.string.DeviceProvisioningActivity_content_progress_no_device, Toast.LENGTH_LONG).show(); - break; - case NETWORK_ERROR: - Toast.makeText(context, R.string.DeviceProvisioningActivity_content_progress_network_error, Toast.LENGTH_LONG).show(); - break; - case KEY_ERROR: - Toast.makeText(context, R.string.DeviceProvisioningActivity_content_progress_key_error, Toast.LENGTH_LONG).show(); - break; - case LIMIT_EXCEEDED: - Toast.makeText(context, R.string.DeviceProvisioningActivity_sorry_you_have_too_many_devices_linked_already, Toast.LENGTH_LONG).show(); - break; - case BAD_CODE: - Toast.makeText(context, R.string.DeviceActivity_sorry_this_is_not_a_valid_device_link_qr_code, Toast.LENGTH_LONG).show(); - break; - } - - getSupportFragmentManager().popBackStackImmediate(); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } -} diff --git a/src/org/thoughtcrime/securesms/DeviceAddFragment.java b/src/org/thoughtcrime/securesms/DeviceAddFragment.java deleted file mode 100644 index 4090e82bb..000000000 --- a/src/org/thoughtcrime/securesms/DeviceAddFragment.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.thoughtcrime.securesms; - -import android.animation.Animator; -import android.annotation.TargetApi; -import android.content.Context; -import android.content.res.Configuration; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewAnimationUtils; -import android.view.ViewGroup; -import android.view.animation.DecelerateInterpolator; -import android.widget.ImageView; -import android.widget.LinearLayout; - -import com.google.zxing.BinaryBitmap; -import com.google.zxing.ChecksumException; -import com.google.zxing.FormatException; -import com.google.zxing.NotFoundException; -import com.google.zxing.PlanarYUVLuminanceSource; -import com.google.zxing.Result; -import com.google.zxing.common.HybridBinarizer; -import com.google.zxing.qrcode.QRCodeReader; - -import org.thoughtcrime.securesms.components.camera.CameraView; -import org.thoughtcrime.securesms.components.camera.CameraView.PreviewCallback; -import org.thoughtcrime.securesms.components.camera.CameraView.PreviewFrame; -import org.thoughtcrime.securesms.qr.ScanListener; -import org.thoughtcrime.securesms.qr.ScanningThread; -import org.thoughtcrime.securesms.util.Util; -import org.thoughtcrime.securesms.util.ViewUtil; - -public class DeviceAddFragment extends Fragment { - - private ViewGroup container; - private LinearLayout overlay; - private ImageView devicesImage; - private CameraView scannerView; - private ScanningThread scanningThread; - private ScanListener scanListener; - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) { - this.container = ViewUtil.inflate(inflater, viewGroup, R.layout.device_add_fragment); - this.overlay = ViewUtil.findById(this.container, R.id.overlay); - this.scannerView = ViewUtil.findById(this.container, R.id.scanner); - this.devicesImage = ViewUtil.findById(this.container, R.id.devices); - - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { - this.overlay.setOrientation(LinearLayout.HORIZONTAL); - } else { - this.overlay.setOrientation(LinearLayout.VERTICAL); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - this.container.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) - { - v.removeOnLayoutChangeListener(this); - - Animator reveal = ViewAnimationUtils.createCircularReveal(v, right, bottom, 0, (int) Math.hypot(right, bottom)); - reveal.setInterpolator(new DecelerateInterpolator(2f)); - reveal.setDuration(800); - reveal.start(); - } - }); - } - - return this.container; - } - - @Override - public void onResume() { - super.onResume(); - this.scanningThread = new ScanningThread(); - this.scanningThread.setScanListener(scanListener); - this.scannerView.onResume(); - this.scannerView.setPreviewCallback(scanningThread); - this.scanningThread.start(); - } - - @Override - public void onPause() { - super.onPause(); - this.scannerView.onPause(); - this.scanningThread.stopScanning(); - } - - @Override - public void onConfigurationChanged(Configuration newConfiguration) { - super.onConfigurationChanged(newConfiguration); - - this.scannerView.onPause(); - - if (newConfiguration.orientation == Configuration.ORIENTATION_LANDSCAPE) { - overlay.setOrientation(LinearLayout.HORIZONTAL); - } else { - overlay.setOrientation(LinearLayout.VERTICAL); - } - - this.scannerView.onResume(); - this.scannerView.setPreviewCallback(scanningThread); - } - - - public ImageView getDevicesImage() { - return devicesImage; - } - - public void setScanListener(ScanListener scanListener) { - this.scanListener = scanListener; - - if (this.scanningThread != null) { - this.scanningThread.setScanListener(scanListener); - } - } - - -} diff --git a/src/org/thoughtcrime/securesms/DeviceLinkFragment.java b/src/org/thoughtcrime/securesms/DeviceLinkFragment.java deleted file mode 100644 index 21487e213..000000000 --- a/src/org/thoughtcrime/securesms/DeviceLinkFragment.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.thoughtcrime.securesms; - -import android.content.res.Configuration; -import android.net.Uri; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; - -public class DeviceLinkFragment extends Fragment implements View.OnClickListener { - - private LinearLayout container; - private LinkClickedListener linkClickedListener; - private Uri uri; - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) { - this.container = (LinearLayout) inflater.inflate(R.layout.device_link_fragment, container, false); - this.container.findViewById(R.id.link_device).setOnClickListener(this); - - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { - container.setOrientation(LinearLayout.HORIZONTAL); - } else { - container.setOrientation(LinearLayout.VERTICAL); - } - - return this.container; - } - - @Override - public void onConfigurationChanged(Configuration newConfiguration) { - if (newConfiguration.orientation == Configuration.ORIENTATION_LANDSCAPE) { - container.setOrientation(LinearLayout.HORIZONTAL); - } else { - container.setOrientation(LinearLayout.VERTICAL); - } - } - - public void setLinkClickedListener(Uri uri, LinkClickedListener linkClickedListener) { - this.uri = uri; - this.linkClickedListener = linkClickedListener; - } - - @Override - public void onClick(View v) { - if (linkClickedListener != null) { - linkClickedListener.onLink(uri); - } - } - - public interface LinkClickedListener { - public void onLink(Uri uri); - } -} diff --git a/src/org/thoughtcrime/securesms/DeviceListFragment.java b/src/org/thoughtcrime/securesms/DeviceListFragment.java deleted file mode 100644 index b504947b8..000000000 --- a/src/org/thoughtcrime/securesms/DeviceListFragment.java +++ /dev/null @@ -1,217 +0,0 @@ -package org.thoughtcrime.securesms; - -import android.app.Activity; -import android.content.Context; -import android.content.DialogInterface; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.app.ListFragment; -import android.support.v4.app.LoaderManager; -import android.support.v4.content.Loader; -import android.support.v7.app.AlertDialog; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.ListView; -import android.widget.Toast; - -import com.melnykov.fab.FloatingActionButton; - -import org.thoughtcrime.securesms.database.loaders.DeviceListLoader; -import org.thoughtcrime.securesms.dependencies.InjectableType; -import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.ViewUtil; -import org.whispersystems.signalservice.api.SignalServiceAccountManager; -import org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo; - -import java.io.IOException; -import java.util.List; -import java.util.Locale; - -import javax.inject.Inject; - -public class DeviceListFragment extends ListFragment - implements LoaderManager.LoaderCallbacks>, - ListView.OnItemClickListener, InjectableType, Button.OnClickListener -{ - - private static final String TAG = DeviceListFragment.class.getSimpleName(); - - @Inject - SignalServiceAccountManager accountManager; - - private Locale locale; - private View empty; - private View progressContainer; - private FloatingActionButton addDeviceButton; - private Button.OnClickListener addDeviceButtonListener; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - this.locale = (Locale) getArguments().getSerializable(PassphraseRequiredActionBarActivity.LOCALE_EXTRA); - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - ApplicationContext.getInstance(activity).injectDependencies(this); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - View view = inflater.inflate(R.layout.device_list_fragment, container, false); - - this.empty = view.findViewById(R.id.empty); - this.progressContainer = view.findViewById(R.id.progress_container); - this.addDeviceButton = ViewUtil.findById(view, R.id.add_device); - this.addDeviceButton.setOnClickListener(this); - - return view; - } - - @Override - public void onActivityCreated(Bundle bundle) { - super.onActivityCreated(bundle); - getLoaderManager().initLoader(0, null, this); - getListView().setOnItemClickListener(this); - } - - public void setAddDeviceButtonListener(Button.OnClickListener listener) { - this.addDeviceButtonListener = listener; - } - - @Override - public Loader> onCreateLoader(int id, Bundle args) { - empty.setVisibility(View.GONE); - progressContainer.setVisibility(View.VISIBLE); - - return new DeviceListLoader(getActivity(), accountManager); - } - - @Override - public void onLoadFinished(Loader> loader, List data) { - progressContainer.setVisibility(View.GONE); - - if (data == null) { - handleLoaderFailed(); - return; - } - - setListAdapter(new DeviceListAdapter(getActivity(), R.layout.device_list_item_view, data, locale)); - - if (data.isEmpty()) { - empty.setVisibility(View.VISIBLE); - TextSecurePreferences.setMultiDevice(getActivity(), false); - } else { - empty.setVisibility(View.GONE); - } - } - - @Override - public void onLoaderReset(Loader> loader) { - setListAdapter(null); - } - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - final String deviceName = ((DeviceListItem)view).getDeviceName(); - final long deviceId = ((DeviceListItem)view).getDeviceId(); - - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setTitle(getActivity().getString(R.string.DeviceListActivity_unlink_s, deviceName)); - builder.setMessage(R.string.DeviceListActivity_by_unlinking_this_device_it_will_no_longer_be_able_to_send_or_receive); - builder.setNegativeButton(android.R.string.cancel, null); - builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - handleDisconnectDevice(deviceId); - } - }); - builder.show(); - } - - private void handleLoaderFailed() { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setMessage(R.string.DeviceListActivity_network_connection_failed); - builder.setPositiveButton(R.string.DeviceListActivity_try_again, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - getLoaderManager().restartLoader(0, null, DeviceListFragment.this); - } - }); - - builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - DeviceListFragment.this.getActivity().onBackPressed(); - } - }); - builder.setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - DeviceListFragment.this.getActivity().onBackPressed(); - } - }); - - builder.show(); - } - - private void handleDisconnectDevice(final long deviceId) { - new ProgressDialogAsyncTask(getActivity(), - R.string.DeviceListActivity_unlinking_device_no_ellipsis, - R.string.DeviceListActivity_unlinking_device) - { - @Override - protected Void doInBackground(Void... params) { - try { - accountManager.removeDevice(deviceId); - } catch (IOException e) { - Log.w(TAG, e); - Toast.makeText(getActivity(), R.string.DeviceListActivity_network_failed, Toast.LENGTH_LONG).show(); - } - return null; - } - - @Override - protected void onPostExecute(Void result) { - super.onPostExecute(result); - getLoaderManager().restartLoader(0, null, DeviceListFragment.this); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - @Override - public void onClick(View v) { - if (addDeviceButtonListener != null) addDeviceButtonListener.onClick(v); - } - - private static class DeviceListAdapter extends ArrayAdapter { - - private final int resource; - private final Locale locale; - - public DeviceListAdapter(Context context, int resource, List objects, Locale locale) { - super(context, resource, objects); - this.resource = resource; - this.locale = locale; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - if (convertView == null) { - convertView = ((Activity)getContext()).getLayoutInflater().inflate(resource, parent, false); - } - - ((DeviceListItem)convertView).set(getItem(position), locale); - - return convertView; - } - } -} diff --git a/src/org/thoughtcrime/securesms/DeviceListItem.java b/src/org/thoughtcrime/securesms/DeviceListItem.java deleted file mode 100644 index 70bc59317..000000000 --- a/src/org/thoughtcrime/securesms/DeviceListItem.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.thoughtcrime.securesms; - -import android.content.Context; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.widget.LinearLayout; -import android.widget.TextView; - -import org.thoughtcrime.securesms.util.DateUtils; -import org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo; - -import java.util.Locale; - -public class DeviceListItem extends LinearLayout { - - private long deviceId; - private TextView name; - private TextView created; - private TextView lastActive; - - public DeviceListItem(Context context) { - super(context); - } - - public DeviceListItem(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - public void onFinishInflate() { - super.onFinishInflate(); - this.name = (TextView) findViewById(R.id.name); - this.created = (TextView) findViewById(R.id.created); - this.lastActive = (TextView) findViewById(R.id.active); - } - - public void set(DeviceInfo deviceInfo, Locale locale) { - if (TextUtils.isEmpty(deviceInfo.getName())) this.name.setText(R.string.DeviceListItem_unnamed_device); - else this.name.setText(deviceInfo.getName()); - - this.created.setText(getContext().getString(R.string.DeviceListItem_linked_s, - DateUtils.getDayPrecisionTimeSpanString(getContext(), - locale, - deviceInfo.getCreated()))); - - this.lastActive.setText(getContext().getString(R.string.DeviceListItem_last_active_s, - DateUtils.getDayPrecisionTimeSpanString(getContext(), - locale, - deviceInfo.getLastSeen()))); - - this.deviceId = deviceInfo.getId(); - } - - public long getDeviceId() { - return deviceId; - } - - public String getDeviceName() { - return name.getText().toString(); - } - -} diff --git a/src/org/thoughtcrime/securesms/DeviceProvisioningActivity.java b/src/org/thoughtcrime/securesms/DeviceProvisioningActivity.java deleted file mode 100644 index 0a1ca583f..000000000 --- a/src/org/thoughtcrime/securesms/DeviceProvisioningActivity.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.thoughtcrime.securesms; - -import android.content.Intent; -import android.os.Bundle; -import android.support.v7.app.AlertDialog; -import android.view.Window; - -public class DeviceProvisioningActivity extends PassphraseRequiredActionBarActivity { - - @SuppressWarnings("unused") - private static final String TAG = DeviceProvisioningActivity.class.getSimpleName(); - - @Override - protected void onPreCreate() { - supportRequestWindowFeature(Window.FEATURE_NO_TITLE); - } - - @Override - protected void onCreate(Bundle bundle, boolean ready) { - assert getSupportActionBar() != null; - getSupportActionBar().hide(); - - AlertDialog dialog = new AlertDialog.Builder(this) - .setTitle(getString(R.string.DeviceProvisioningActivity_link_a_signal_device)) - .setMessage(getString(R.string.DeviceProvisioningActivity_it_looks_like_youre_trying_to_link_a_signal_device_using_a_3rd_party_scanner)) - .setPositiveButton(R.string.DeviceProvisioningActivity_continue, (dialog1, which) -> { - Intent intent = new Intent(DeviceProvisioningActivity.this, DeviceActivity.class); - intent.putExtra("add", true); - startActivity(intent); - finish(); - }) - .setNegativeButton(R.string.DeviceProvisioningActivity_cancel, (dialog12, which) -> { - dialog12.dismiss(); - finish(); - }) - .setOnDismissListener(dialog13 -> finish()) - .create(); - - dialog.setIcon(getResources().getDrawable(R.drawable.icon_dialog)); - dialog.show(); - } -} diff --git a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java index 208e37249..c2cb151e4 100644 --- a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java +++ b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java @@ -6,14 +6,12 @@ import android.util.Log; import org.greenrobot.eventbus.EventBus; import org.thoughtcrime.securesms.BuildConfig; import org.thoughtcrime.securesms.CreateProfileActivity; -import org.thoughtcrime.securesms.DeviceListFragment; import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl; import org.thoughtcrime.securesms.events.ReminderUpdateEvent; import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob; import org.thoughtcrime.securesms.jobs.AvatarDownloadJob; import org.thoughtcrime.securesms.jobs.CleanPreKeysJob; import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob; -import org.thoughtcrime.securesms.jobs.GcmRefreshJob; import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob; import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob; import org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob; @@ -34,7 +32,6 @@ import org.thoughtcrime.securesms.jobs.RetrieveProfileJob; import org.thoughtcrime.securesms.jobs.RotateSignedPreKeyJob; import org.thoughtcrime.securesms.jobs.SendReadReceiptJob; import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment; -import org.thoughtcrime.securesms.preferences.SmsMmsPreferenceFragment; import org.thoughtcrime.securesms.push.SecurityEventListener; import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess; import org.thoughtcrime.securesms.service.MessageRetrievalService; @@ -63,9 +60,7 @@ import dagger.Provides; MultiDeviceGroupUpdateJob.class, MultiDeviceReadUpdateJob.class, MultiDeviceBlockedUpdateJob.class, - DeviceListFragment.class, RefreshAttributesJob.class, - GcmRefreshJob.class, RequestGroupInfoJob.class, PushGroupUpdateJob.class, AvatarDownloadJob.class, diff --git a/src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java b/src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java deleted file mode 100644 index d0d7dedcf..000000000 --- a/src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Copyright (C) 2014 Open Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.thoughtcrime.securesms.jobs; - -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.graphics.BitmapFactory; -import android.support.v4.app.NotificationCompat; -import android.util.Log; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GooglePlayServicesUtil; -import com.google.android.gms.gcm.GoogleCloudMessaging; - -import org.thoughtcrime.securesms.PlayServicesProblemActivity; -import org.thoughtcrime.securesms.R; -import org.thoughtcrime.securesms.dependencies.InjectableType; -import org.thoughtcrime.securesms.jobmanager.JobParameters; -import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirement; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.whispersystems.libsignal.util.guava.Optional; -import org.whispersystems.signalservice.api.SignalServiceAccountManager; -import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException; - -import javax.inject.Inject; - -public class GcmRefreshJob extends ContextJob implements InjectableType { - - private static final String TAG = GcmRefreshJob.class.getSimpleName(); - - public static final String REGISTRATION_ID = "312334754206"; - - @Inject transient SignalServiceAccountManager textSecureAccountManager; - - public GcmRefreshJob(Context context) { - super(context, JobParameters.newBuilder() - .withRequirement(new NetworkRequirement(context)) - .withRetryCount(1) - .create()); - } - - @Override - public void onAdded() {} - - @Override - public void onRun() throws Exception { - if (TextSecurePreferences.isGcmDisabled(context)) return; - - Log.w(TAG, "Reregistering GCM..."); - int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); - - if (result != ConnectionResult.SUCCESS) { - notifyGcmFailure(); - } else { - String gcmId = GoogleCloudMessaging.getInstance(context).register(REGISTRATION_ID); - textSecureAccountManager.setGcmId(Optional.of(gcmId)); - - TextSecurePreferences.setGcmRegistrationId(context, gcmId); - TextSecurePreferences.setGcmRegistrationIdLastSetTime(context, System.currentTimeMillis()); - TextSecurePreferences.setWebsocketRegistered(context, true); - } - } - - @Override - public void onCanceled() { - Log.w(TAG, "GCM reregistration failed after retry attempt exhaustion!"); - } - - @Override - public boolean onShouldRetry(Exception throwable) { - if (throwable instanceof NonSuccessfulResponseCodeException) return false; - return true; - } - - private void notifyGcmFailure() { - Intent intent = new Intent(context, PlayServicesProblemActivity.class); - PendingIntent pendingIntent = PendingIntent.getActivity(context, 1122, intent, PendingIntent.FLAG_CANCEL_CURRENT); - NotificationCompat.Builder builder = new NotificationCompat.Builder(context); - - builder.setSmallIcon(R.drawable.icon_notification); - builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), - R.drawable.ic_action_warning_red)); - builder.setContentTitle(context.getString(R.string.GcmRefreshJob_Permanent_Signal_communication_failure)); - builder.setContentText(context.getString(R.string.GcmRefreshJob_Signal_was_unable_to_register_with_Google_Play_Services)); - builder.setTicker(context.getString(R.string.GcmRefreshJob_Permanent_Signal_communication_failure)); - builder.setVibrate(new long[] {0, 1000}); - builder.setContentIntent(pendingIntent); - - ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)) - .notify(12, builder.build()); - } - -} diff --git a/src/org/thoughtcrime/securesms/preferences/SmsMmsPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/SmsMmsPreferenceFragment.java deleted file mode 100644 index 6de3adde7..000000000 --- a/src/org/thoughtcrime/securesms/preferences/SmsMmsPreferenceFragment.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.thoughtcrime.securesms.preferences; - -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; -import android.os.Bundle; -import android.provider.Settings; -import android.provider.Telephony; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceScreen; - -import org.thoughtcrime.securesms.ApplicationPreferencesActivity; -import org.thoughtcrime.securesms.R; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; - -public class SmsMmsPreferenceFragment extends CorrectedPreferenceFragment { - private static final String KITKAT_DEFAULT_PREF = "pref_set_default"; - private static final String MMS_PREF = "pref_mms_preferences"; - - @Override - public void onCreate(Bundle paramBundle) { - super.onCreate(paramBundle); - - - this.findPreference(MMS_PREF) - .setOnPreferenceClickListener(new ApnPreferencesClickListener()); - - initializePlatformSpecificOptions(); - } - - @Override - public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) { - addPreferencesFromResource(R.xml.preferences_sms_mms); - } - - @Override - public void onResume() { - super.onResume(); - ((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.preferences__sms_mms); - - initializeDefaultPreference(); - } - - private void initializePlatformSpecificOptions() { - PreferenceScreen preferenceScreen = getPreferenceScreen(); - Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF); - Preference allSmsPreference = findPreference(TextSecurePreferences.ALL_SMS_PREF); - Preference allMmsPreference = findPreference(TextSecurePreferences.ALL_MMS_PREF); - Preference manualMmsPreference = findPreference(MMS_PREF); - - if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { - if (allSmsPreference != null) preferenceScreen.removePreference(allSmsPreference); - if (allMmsPreference != null) preferenceScreen.removePreference(allMmsPreference); - } else if (defaultPreference != null) { - preferenceScreen.removePreference(defaultPreference); - } - - if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && manualMmsPreference != null) { - preferenceScreen.removePreference(manualMmsPreference); - } - } - - private void initializeDefaultPreference() { - if (VERSION.SDK_INT < VERSION_CODES.KITKAT) return; - - Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF); - if (Util.isDefaultSmsProvider(getActivity())) { - if (VERSION.SDK_INT < VERSION_CODES.M) defaultPreference.setIntent(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); - if (VERSION.SDK_INT < VERSION_CODES.N) defaultPreference.setIntent(new Intent(Settings.ACTION_SETTINGS)); - else defaultPreference.setIntent(new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS)); - - defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_enabled)); - defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_change_your_default_sms_app)); - } else { - Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); - intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getActivity().getPackageName()); - defaultPreference.setIntent(intent); - defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_disabled)); - defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_make_signal_your_default_sms_app)); - } - } - - private class ApnPreferencesClickListener implements Preference.OnPreferenceClickListener { - - @Override - public boolean onPreferenceClick(Preference preference) { - Fragment fragment = new MmsPreferencesFragment(); - FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); - FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); - fragmentTransaction.replace(android.R.id.content, fragment); - fragmentTransaction.addToBackStack(null); - fragmentTransaction.commit(); - - return true; - } - } - - public static CharSequence getSummary(Context context) { - final String on = context.getString(R.string.ApplicationPreferencesActivity_on); - final String onCaps = context.getString(R.string.ApplicationPreferencesActivity_On); - final String off = context.getString(R.string.ApplicationPreferencesActivity_off); - final String offCaps = context.getString(R.string.ApplicationPreferencesActivity_Off); - final int smsMmsSummaryResId = R.string.ApplicationPreferencesActivity_sms_mms_summary; - - boolean postKitkatSMS = Util.isDefaultSmsProvider(context); - boolean preKitkatSMS = TextSecurePreferences.isInterceptAllSmsEnabled(context); - boolean preKitkatMMS = TextSecurePreferences.isInterceptAllMmsEnabled(context); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - if (postKitkatSMS) return onCaps; - else return offCaps; - } else { - if (preKitkatSMS && preKitkatMMS) return onCaps; - else if (preKitkatSMS && !preKitkatMMS) return context.getString(smsMmsSummaryResId, on, off); - else if (!preKitkatSMS && preKitkatMMS) return context.getString(smsMmsSummaryResId, off, on); - else return offCaps; - } - } -}