Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93a0969c authored by Luis Vidal's avatar Luis Vidal
Browse files

Prevent crash if weather settings activity can't be found

Each weather provider service may define a settings activity which
will be automatically launched when the user selects the provider.
If such activity can't be found, an ActivityNotFoundException is
thrown. This patch adds a try/catch block to avoid crashing the
settings app if the activity can't be found

A toast will be displayed to notify the user. Otherwise, the user
would never know why the settings gear is doing nothing

Change-Id: I3c3d54ce8f9131353077c34a2f821ec6b0fc0268
TICKET: CYNGNOS-2478
(cherry picked from commit f1e42d87)
parent 34635301
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1168,6 +1168,7 @@
    <string name="weather_settings_title">Weather</string>
    <string name="weather_settings_no_services_prompt">No weather provider services installed</string>
    <string name="weather_settings_button">Provider settings</string>
    <string name="weather_settings_activity_not_found">Unable to launch the settings menu of this provider</string>

    <string name="background_data_access">Background data access</string>
    <string name="allow_background_both">Over mobile data &amp; WiFi</string>
+20 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.cyanogenmod;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -32,6 +33,7 @@ import android.os.UserHandle;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -41,6 +43,7 @@ import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.content.PackageMonitor;
import com.android.internal.os.BackgroundThread;
import com.android.settings.R;
@@ -295,7 +298,22 @@ public class WeatherServiceSettings extends SettingsPreferenceFragment {

        private void launchSettingsActivity(WeatherProviderServiceInfo info) {
            if (info != null && info.settingsComponentName != null) {
                try {
                    mContext.startActivity(new Intent().setComponent(info.settingsComponentName));
                } catch (ActivityNotFoundException e) {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            Toast t = Toast.makeText(mContext,
                                    R.string.weather_settings_activity_not_found,
                                        Toast.LENGTH_LONG);
                            TextView v = (TextView) t.getView().findViewById(android.R.id.message);
                            if (v != null) v.setGravity(Gravity.CENTER);
                            t.show();
                        }
                    });
                    Log.w(TAG, info.settingsComponentName + " not found");
                }
            }
        }

@@ -323,9 +341,7 @@ public class WeatherServiceSettings extends SettingsPreferenceFragment {
            CMSettings.Secure.putString(mContext.getContentResolver(),
                    CMSettings.Secure.WEATHER_PROVIDER_SERVICE,
                        info.componentName.flattenToString());
            if (info.settingsComponentName != null) {
                mContext.startActivity(new Intent().setComponent(info.settingsComponentName));
            }
            launchSettingsActivity(info);
            notifyDataSetChanged();
        }