summaryrefslogtreecommitdiff
path: root/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers')
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/DeviceCompatibilityUnsupportedFeaturesQuickFix.java113
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/ImpliedFeaturesGenerator.java71
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/ImpliedFeaturesMarkerResolution.java100
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/MissingMinSdkQuickFix.java110
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/MissingPermissionsQuickFix.java104
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/QuickFixGenerator.java133
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/UneededMaxSdkQuickFix.java96
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/UnneededPermissionsQuickFix.java101
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/i18n/CheckersUiNLS.java65
-rw-r--r--src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/i18n/messages.properties37
10 files changed, 930 insertions, 0 deletions
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/DeviceCompatibilityUnsupportedFeaturesQuickFix.java b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/DeviceCompatibilityUnsupportedFeaturesQuickFix.java
new file mode 100644
index 0000000..d53b53b
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/DeviceCompatibilityUnsupportedFeaturesQuickFix.java
@@ -0,0 +1,113 @@
+/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.motorolamobility.preflighting.checkers.ui;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+
+import com.motorola.studio.android.common.utilities.EclipseUtils;
+import com.motorola.studio.android.manifest.AndroidProjectManifestFile;
+import com.motorola.studio.android.model.manifest.AndroidManifestFile;
+import com.motorola.studio.android.model.manifest.dom.ManifestNode;
+import com.motorola.studio.android.model.manifest.dom.UsesFeatureNode;
+import com.motorolamobility.preflighting.checkers.ui.i18n.CheckersUiNLS;
+
+/**
+ * This class implements the fix for device compatibility - unsupported features condition.
+ * The fix consists in adding <uses-feature android:name="featureName" android:required="false"/> to AndroidManifest.xml.
+ */
+public class DeviceCompatibilityUnsupportedFeaturesQuickFix implements IMarkerResolution2
+{
+
+ private static final String FALSE = "false"; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution#getLabel()
+ */
+ public String getLabel()
+ {
+ return CheckersUiNLS.DeviceCompatibilityUnsupportedFeaturesQuickFix_Label;
+ }
+
+ /**
+ * Adds android:required="false" for the feature AndroidManifest.xml.
+ *
+ * @param marker contains the feature that must be made NOT REQUIRED in AndroidManifest.xml.
+ *
+ * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker)
+ */
+ @SuppressWarnings("unchecked")
+ public void run(IMarker marker)
+ {
+ try
+ {
+ //get the AndroidManifest file
+ IProject project = marker.getResource().getProject();
+ AndroidManifestFile manifestFile = AndroidProjectManifestFile.getFromProject(project);
+ ManifestNode manifestNode = manifestFile.getManifestNode();
+
+ //get the feature that must be made NOT REQUIRED, generated from app validator
+ List<Object> attributes =
+ (List<Object>) marker.getAttribute(QuickFixGenerator.QUICK_FIX_ID);
+
+ for (Object featureId : attributes)
+ {
+ UsesFeatureNode usesFeatureNode =
+ manifestNode.getUsesFeatureNode((String) featureId);
+ if (usesFeatureNode == null)
+ {
+ //uses-feature element does not exist - add the element uses feature node
+ usesFeatureNode = new UsesFeatureNode((String) featureId);
+ manifestNode.addUsesFeatureNode(usesFeatureNode);
+ }
+ //in both cases (uses-feature element exists or not) - add/update the required attribute
+ usesFeatureNode.setRequired(Boolean.parseBoolean(FALSE));
+ }
+
+ //save the project with the new/updated uses-feature
+ AndroidProjectManifestFile.saveToProject(project, manifestFile, true);
+
+ marker.delete();
+ }
+ catch (Exception e)
+ {
+ EclipseUtils.showErrorDialog(CheckersUiNLS.QuickFix_MarkerResolutionFailed,
+ CheckersUiNLS.QuickFix_CouldNotFixTheProblem + e.getMessage());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getDescription()
+ */
+ public String getDescription()
+ {
+ return CheckersUiNLS.DeviceCompatibilityUnsupportedFeaturesQuickFix_Description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getImage()
+ */
+ public Image getImage()
+ {
+ return null;
+ }
+
+} \ No newline at end of file
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/ImpliedFeaturesGenerator.java b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/ImpliedFeaturesGenerator.java
new file mode 100644
index 0000000..4951ec5
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/ImpliedFeaturesGenerator.java
@@ -0,0 +1,71 @@
+/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.motorolamobility.preflighting.checkers.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolution2;
+import org.eclipse.ui.IMarkerResolutionGenerator2;
+import com.motorola.studio.android.common.log.StudioLogger;
+
+public class ImpliedFeaturesGenerator implements IMarkerResolutionGenerator2
+{
+
+ public IMarkerResolution[] getResolutions(IMarker marker)
+ {
+ List<IMarkerResolution2> resolutions = new ArrayList<IMarkerResolution2>();
+
+ try
+ {
+ if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.impliedFeaturesMarker"))
+ {
+ resolutions.add(new ImpliedFeaturesMarkerResolution());
+ }
+ }
+ catch (CoreException e) {
+ StudioLogger.error("Requested marker does not exist: ", e.getMessage());
+ }
+ return resolutions.toArray(new IMarkerResolution2[resolutions.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolutionGenerator2#hasResolutions(org.eclipse.core.resources.IMarker)
+ */
+ public boolean hasResolutions(IMarker marker)
+ {
+ boolean hasResolutions = false;
+ try
+ {
+ if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.impliedFeaturesMarker"))
+ {
+ hasResolutions = true;
+ }
+ }
+ catch (CoreException e)
+ {
+ StudioLogger.error("Requested marker does not exist: ", e.getMessage());
+ }
+
+ return hasResolutions;
+ }
+
+}
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/ImpliedFeaturesMarkerResolution.java b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/ImpliedFeaturesMarkerResolution.java
new file mode 100644
index 0000000..b823d41
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/ImpliedFeaturesMarkerResolution.java
@@ -0,0 +1,100 @@
+/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.motorolamobility.preflighting.checkers.ui;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+
+import com.motorola.studio.android.common.exception.AndroidException;
+import com.motorola.studio.android.common.utilities.EclipseUtils;
+import com.motorola.studio.android.manifest.AndroidProjectManifestFile;
+import com.motorola.studio.android.model.manifest.AndroidManifestFile;
+import com.motorola.studio.android.model.manifest.dom.ManifestNode;
+import com.motorola.studio.android.model.manifest.dom.UsesFeatureNode;
+import com.motorolamobility.preflighting.checkers.ui.i18n.CheckersUiNLS;
+
+/**
+ * MarkerResolution responsible for adding the implied feature by permission as uses-feature manifest node.
+ */
+public class ImpliedFeaturesMarkerResolution implements IMarkerResolution2
+{
+
+ public String getLabel()
+ {
+ return CheckersUiNLS.ImpliedFeaturesMarkerResolution_Label;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void run(IMarker marker)
+ {
+ IResource resource = marker.getResource();
+ AndroidManifestFile manifestFile;
+ try
+ {
+ IProject project = resource.getProject();
+ manifestFile = AndroidProjectManifestFile.getFromProject(project);
+ ManifestNode manifestNode = manifestFile.getManifestNode();
+
+ List<Object> attributes =
+ (List<Object>) marker.getAttribute(QuickFixGenerator.QUICK_FIX_ID);
+ for(Object attribute : attributes)
+ {
+ List<String> impliedFeatures = (List<String>) attribute;
+ for(String impliedFeature : impliedFeatures)
+ {
+ UsesFeatureNode usesFeatureNode = manifestNode.getUsesFeatureNode(impliedFeature);
+ if(usesFeatureNode == null) //User has not yet added it!
+ {
+ usesFeatureNode = new UsesFeatureNode(impliedFeature);
+ manifestNode.addUsesFeatureNode(usesFeatureNode);
+ }
+ }
+ }
+ AndroidProjectManifestFile.saveToProject(project, manifestFile, true);
+
+ marker.delete();
+ }
+ catch (AndroidException e)
+ {
+ EclipseUtils.showErrorDialog(CheckersUiNLS.ImpliedFeaturesMarkerResolution_Fail_Msg_Dlg_Title, CheckersUiNLS.ImpliedFeaturesMarkerResolution_Fail_Msg_Save_Manifest);
+ }
+ catch (CoreException e)
+ {
+ EclipseUtils.showErrorDialog(CheckersUiNLS.ImpliedFeaturesMarkerResolution_Fail_Msg_Dlg_Title, CheckersUiNLS.ImpliedFeaturesMarkerResolution_Fail_Msg_Manipulate_Manifest);
+ }
+
+ }
+
+ public Image getImage()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getDescription()
+ */
+ public String getDescription()
+ {
+ return null; //There's no additional description.
+ }
+
+}
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/MissingMinSdkQuickFix.java b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/MissingMinSdkQuickFix.java
new file mode 100644
index 0000000..7ae3d1b
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/MissingMinSdkQuickFix.java
@@ -0,0 +1,110 @@
+/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.motorolamobility.preflighting.checkers.ui;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+
+import com.motorola.studio.android.common.utilities.AndroidUtils;
+import com.motorola.studio.android.common.utilities.EclipseUtils;
+import com.motorola.studio.android.manifest.AndroidProjectManifestFile;
+import com.motorola.studio.android.model.manifest.AndroidManifestFile;
+import com.motorola.studio.android.model.manifest.dom.ManifestNode;
+import com.motorola.studio.android.model.manifest.dom.UsesSDKNode;
+import com.motorolamobility.preflighting.checkers.ui.i18n.CheckersUiNLS;
+
+/**
+ * This class implements the fix for Android Market filter - Missing minSdk condition.
+ * The fix consists in adding &lt;uses-sdk android:minSdkVersion="targetDeclaredOnproject.properties"/&gt; to AndroidManifest.xml.
+ */
+public class MissingMinSdkQuickFix implements IMarkerResolution2
+{
+ private static final String ANDROID_PREFIX = "android-";
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution#getLabel()
+ */
+ public String getLabel()
+ {
+ return CheckersUiNLS.MissingMinSdkQuickFix_Label;
+ }
+
+ /**
+ * Adds android:minSdkVersion="targetDeclaredOnproject.properties" for the uses-sdk in AndroidManifest.xml.
+ *
+ * @param marker
+ *
+ * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker)
+ */
+ public void run(IMarker marker)
+ {
+ try
+ {
+ //get the AndroidManifest file
+ IProject project = marker.getResource().getProject();
+ AndroidManifestFile manifestFile = AndroidProjectManifestFile.getFromProject(project);
+ ManifestNode manifestNode = manifestFile.getManifestNode();
+
+ File projectAPITargetFile =
+ AndroidUtils.getAndroidTargetPathForProject(project.getLocation().toFile());
+ String projectTargetAPI = projectAPITargetFile.getName();
+
+ UsesSDKNode usesSDKNode = manifestNode.getUsesSdkNode();
+ if (usesSDKNode == null)
+ {
+ //element uses-sdk does not exist - add the entire element with minSdkVersion attribute
+ usesSDKNode = new UsesSDKNode();
+ manifestNode.addUsesSdkNode(usesSDKNode);
+ }
+ //in both cases (if element uses-sdk exists or not) - add minSdkVersion attribute
+ if (projectTargetAPI.contains(ANDROID_PREFIX))
+ {
+ projectTargetAPI = projectTargetAPI.replace(ANDROID_PREFIX, "");
+ }
+ usesSDKNode.setMinSdkVersion(projectTargetAPI);
+
+ //save the project with the new/updated uses-sdk element
+ AndroidProjectManifestFile.saveToProject(project, manifestFile, true);
+
+ marker.delete();
+ }
+ catch (Exception e)
+ {
+ EclipseUtils.showErrorDialog(CheckersUiNLS.QuickFix_MarkerResolutionFailed,
+ CheckersUiNLS.QuickFix_CouldNotFixTheProblem + e.getMessage());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getDescription()
+ */
+ public String getDescription()
+ {
+ return CheckersUiNLS.MissingMinSdkQuickFix_Description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getImage()
+ */
+ public Image getImage()
+ {
+ return null;
+ }
+}
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/MissingPermissionsQuickFix.java b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/MissingPermissionsQuickFix.java
new file mode 100644
index 0000000..927026d
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/MissingPermissionsQuickFix.java
@@ -0,0 +1,104 @@
+/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.motorolamobility.preflighting.checkers.ui;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+
+import com.motorola.studio.android.common.utilities.EclipseUtils;
+import com.motorola.studio.android.manifest.AndroidProjectManifestFile;
+import com.motorola.studio.android.model.manifest.AndroidManifestFile;
+import com.motorola.studio.android.model.manifest.dom.ManifestNode;
+import com.motorola.studio.android.model.manifest.dom.UsesPermissionNode;
+import com.motorolamobility.preflighting.checkers.ui.i18n.CheckersUiNLS;
+
+/**
+ * This class implements the fix for missing permissions condition.
+ * The fix consists in adding all missing permissions to AndroidManifest.xml.
+ */
+public class MissingPermissionsQuickFix implements IMarkerResolution2
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution#getLabel()
+ */
+ public String getLabel()
+ {
+ return CheckersUiNLS.MissingPermissionsQuickFix_Label;
+ }
+
+ /**
+ * Adds all missing permissions to AndroidManifest.xml.
+ *
+ * @param marker contains the list of missing permissions that must be added to AndroidManifest.xml.
+ *
+ * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker)
+ */
+ @SuppressWarnings("unchecked")
+ public void run(IMarker marker)
+ {
+ try
+ {
+ //get the AndroidManifest file
+ IProject project = marker.getResource().getProject();
+ AndroidManifestFile manifestFile = AndroidProjectManifestFile.getFromProject(project);
+ ManifestNode manifestNode = manifestFile.getManifestNode();
+
+ //get the list of missing permissions, generated from app validator
+ List<Object> attributes =
+ (List<Object>) marker.getAttribute(QuickFixGenerator.QUICK_FIX_ID);
+
+ //iterate over the list of missing permissions, adding them to AndroidManifest file
+ for (Object missingPermission : attributes)
+ {
+ manifestNode.addUsesPermissionNode(new UsesPermissionNode(
+ (String) missingPermission));
+ }
+
+ //save the project with the new permissions
+ AndroidProjectManifestFile.saveToProject(project, manifestFile, true);
+
+ marker.delete();
+ }
+ catch (Exception e)
+ {
+ EclipseUtils.showErrorDialog("Marker resolution fail.",
+ "Missing permissions quick fix could not fix the problem: " + e.getMessage());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getDescription()
+ */
+ public String getDescription()
+ {
+ return CheckersUiNLS.MissingPermissionsQuickFix_Description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getImage()
+ */
+ public Image getImage()
+ {
+ return null;
+ }
+
+} \ No newline at end of file
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/QuickFixGenerator.java b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/QuickFixGenerator.java
new file mode 100644
index 0000000..399c0c1
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/QuickFixGenerator.java
@@ -0,0 +1,133 @@
+/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.motorolamobility.preflighting.checkers.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.ui.IMarkerResolution2;
+import org.eclipse.ui.IMarkerResolutionGenerator2;
+
+import com.motorolamobility.preflighting.core.logging.PreflightingLogger;
+
+/**
+ * This class is responsible for checking which markers has quick fixes, and in the cases that a quick fix
+ * is available, it returns the class that implements the fix.
+ * */
+
+public class QuickFixGenerator implements IMarkerResolutionGenerator2
+{
+ /**
+ * AppValidator quick fix identifier.
+ * */
+ public static final String QUICK_FIX_ID = "QuickFix";
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolutionGenerator#getResolutions(org.eclipse.core.resources.IMarker)
+ */
+ public IMarkerResolution2[] getResolutions(IMarker marker)
+ {
+ //list of possible resolutions for the given marker
+ List<IMarkerResolution2> resolutions = new ArrayList<IMarkerResolution2>();
+
+ try
+ {
+ //check the marker type to associate the proper marker resolution class(es).
+ if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.missingPermissionsMarker"))
+ {
+ resolutions.add(new MissingPermissionsQuickFix());
+ }
+ else if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.unneededPermissionsMarker"))
+ {
+ resolutions.add(new UnneededPermissionsQuickFix());
+ }
+ else if (marker
+ .getType()
+ .equals("com.motorolamobility.preflighting.checkers.ui.deviceCompatibilityUnsupportedFeaturesMarker"))
+ {
+ resolutions.add(new DeviceCompatibilityUnsupportedFeaturesQuickFix());
+ }
+ else if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.googlePlayFiltersMissingMinSDK"))
+ {
+ resolutions.add(new MissingMinSdkQuickFix());
+ }
+ else if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.googlePlayFiltersUneededMaxSDK"))
+ {
+ resolutions.add(new UneededMaxSdkQuickFix());
+ }
+ }
+ catch (CoreException e)
+ {
+ PreflightingLogger.info(QuickFixGenerator.class,
+ "Problem retrieving marker resolutions: " + e.getMessage());
+ }
+
+ return resolutions.toArray(new IMarkerResolution2[resolutions.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolutionGenerator2#hasResolutions(org.eclipse.core.resources.IMarker)
+ */
+ public boolean hasResolutions(IMarker marker)
+ {
+ try
+ {
+ //check if the marker type has at least one resolution available.
+ if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.missingPermissionsMarker"))
+ {
+ return true;
+ }
+ else if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.unneededPermissionsMarker"))
+ {
+ return true;
+ }
+ else if (marker
+ .getType()
+ .equals("com.motorolamobility.preflighting.checkers.ui.deviceCompatibilityUnsupportedFeaturesMarker"))
+ {
+ return true;
+ }
+ else if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.googlePlayFiltersMissingMinSDK"))
+ {
+ return true;
+ }
+ else if (marker.getType().equals(
+ "com.motorolamobility.preflighting.checkers.ui.googlePlayFiltersUneededMaxSDK"))
+ {
+ return true;
+ }
+ }
+ catch (CoreException e)
+ {
+ PreflightingLogger.info(QuickFixGenerator.class,
+ "Problem checking if marker has resolutions: " + e.getMessage());
+ }
+
+ //no resolution found for this marker
+ return false;
+ }
+
+} \ No newline at end of file
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/UneededMaxSdkQuickFix.java b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/UneededMaxSdkQuickFix.java
new file mode 100644
index 0000000..56b72be
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/UneededMaxSdkQuickFix.java
@@ -0,0 +1,96 @@
+/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.motorolamobility.preflighting.checkers.ui;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+
+import com.motorola.studio.android.common.utilities.EclipseUtils;
+import com.motorola.studio.android.manifest.AndroidProjectManifestFile;
+import com.motorola.studio.android.model.manifest.AndroidManifestFile;
+import com.motorola.studio.android.model.manifest.dom.ManifestNode;
+import com.motorola.studio.android.model.manifest.dom.UsesSDKNode;
+import com.motorolamobility.preflighting.checkers.ui.i18n.CheckersUiNLS;
+
+/**
+ * Removes unneeded maxSdkVersion from AndroidManifest.xml.
+ */
+public class UneededMaxSdkQuickFix implements IMarkerResolution2
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution#getLabel()
+ */
+ public String getLabel()
+ {
+ return CheckersUiNLS.UneededMaxSdkQuickFix_Label;
+ }
+
+ /**
+ * Removes maxSdkVersion from AndroidManifest.xml.
+ *
+ * @param marker
+ *
+ * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker)
+ */
+ public void run(IMarker marker)
+ {
+ try
+ {
+ //get the AndroidManifest file
+ IProject project = marker.getResource().getProject();
+ AndroidManifestFile manifestFile = AndroidProjectManifestFile.getFromProject(project);
+ ManifestNode manifestNode = manifestFile.getManifestNode();
+
+ UsesSDKNode usesSDKNode = manifestNode.getUsesSdkNode();
+ if (usesSDKNode != null)
+ {
+ if (usesSDKNode.getPropMaxSdkVersion() != null)
+ {
+ usesSDKNode.setPropMaxSdkVersion(null);
+
+ //save the project with the new permissions
+ AndroidProjectManifestFile.saveToProject(project, manifestFile, true);
+ }
+ }
+ marker.delete();
+ }
+ catch (Exception e)
+ {
+ EclipseUtils.showErrorDialog(CheckersUiNLS.QuickFix_MarkerResolutionFailed,
+ CheckersUiNLS.QuickFix_CouldNotFixTheProblem + e.getMessage());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getDescription()
+ */
+ public String getDescription()
+ {
+ return CheckersUiNLS.UneededMaxSdkQuickFix_Description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getImage()
+ */
+ public Image getImage()
+ {
+ return null;
+ }
+
+}
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/UnneededPermissionsQuickFix.java b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/UnneededPermissionsQuickFix.java
new file mode 100644
index 0000000..dca1eed
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/UnneededPermissionsQuickFix.java
@@ -0,0 +1,101 @@
+/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.motorolamobility.preflighting.checkers.ui;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+
+import com.motorola.studio.android.common.utilities.EclipseUtils;
+import com.motorola.studio.android.manifest.AndroidProjectManifestFile;
+import com.motorola.studio.android.model.manifest.AndroidManifestFile;
+import com.motorola.studio.android.model.manifest.dom.ManifestNode;
+import com.motorolamobility.preflighting.checkers.ui.i18n.CheckersUiNLS;
+
+/**
+ * This class implements the fix for unneeded permissions condition.
+ * The fix consists in removing all permissions that are not needed.
+ *
+ */
+public class UnneededPermissionsQuickFix implements IMarkerResolution2
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution#getLabel()
+ */
+ public String getLabel()
+ {
+ return CheckersUiNLS.UnneededPermissionsQuickFix_Label;
+ }
+
+ /**
+ * Removes all unneeded permissions from AndroidManifest.xml.
+ *
+ * @param marker contains the list of unneeded permissions that must be removed from AndroidManifest.xml.
+ * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker)
+ */
+ @SuppressWarnings("unchecked")
+ public void run(IMarker marker)
+ {
+ try
+ {
+ //get the AndroidManifest file
+ IProject project = marker.getResource().getProject();
+ AndroidManifestFile manifestFile = AndroidProjectManifestFile.getFromProject(project);
+ ManifestNode manifestNode = manifestFile.getManifestNode();
+
+ //get the list of unneeded permissions to be removed from AndroidManifest
+ List<Object> attributes =
+ (List<Object>) marker.getAttribute(QuickFixGenerator.QUICK_FIX_ID);
+
+ //iterate over the list of unneeded permissions removing them
+ for (Object unneedPermission : attributes)
+ {
+ manifestNode.removeUsesPermissionNode((String) unneedPermission);
+ }
+
+ //save the project with the unneeded permissions removed
+ AndroidProjectManifestFile.saveToProject(project, manifestFile, true);
+
+ marker.delete();
+ }
+ catch (Exception e)
+ {
+ EclipseUtils.showErrorDialog("Marker resolution fail.", "Unneeded permissions quick fix could not fix the problem: " + e.getMessage());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getDescription()
+ */
+ public String getDescription()
+ {
+ return CheckersUiNLS.UnneededPermissionsQuickFix_Description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IMarkerResolution2#getImage()
+ */
+ public Image getImage()
+ {
+ return null;
+ }
+
+}
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/i18n/CheckersUiNLS.java b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/i18n/CheckersUiNLS.java
new file mode 100644
index 0000000..7e2e489
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/i18n/CheckersUiNLS.java
@@ -0,0 +1,65 @@
+/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.motorolamobility.preflighting.checkers.ui.i18n;
+
+import org.eclipse.osgi.util.NLS;
+
+public class CheckersUiNLS extends NLS
+{
+ private static final String BUNDLE_NAME = "com.motorolamobility.preflighting.checkers.ui.i18n.messages"; //$NON-NLS-1$
+
+ public static String MissingPermissionsQuickFix_Description;
+
+ public static String MissingPermissionsQuickFix_Label;
+
+ public static String UnneededPermissionsQuickFix_Description;
+
+ public static String UnneededPermissionsQuickFix_Label;
+
+ public static String DeviceCompatibilityUnsupportedFeaturesQuickFix_Description;
+
+ public static String QuickFix_CouldNotFixTheProblem;
+
+ public static String DeviceCompatibilityUnsupportedFeaturesQuickFix_Label;
+
+ public static String QuickFix_MarkerResolutionFailed;
+
+ public static String MissingMinSdkQuickFix_Description;
+
+ public static String MissingMinSdkQuickFix_Label;
+
+ public static String UneededMaxSdkQuickFix_Description;
+
+ public static String UneededMaxSdkQuickFix_Label;
+
+ public static String ImpliedFeaturesMarkerResolution_Fail_Msg_Dlg_Title;
+
+ public static String ImpliedFeaturesMarkerResolution_Label;
+
+ public static String ImpliedFeaturesMarkerResolution_Fail_Msg_Manipulate_Manifest;
+
+ public static String ImpliedFeaturesMarkerResolution_Fail_Msg_Save_Manifest;
+
+ static
+ {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, CheckersUiNLS.class);
+ }
+
+ private CheckersUiNLS()
+ {
+ }
+}
diff --git a/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/i18n/messages.properties b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/i18n/messages.properties
new file mode 100644
index 0000000..436d397
--- /dev/null
+++ b/src/plugins/preflighting.checkers.ui/src/com/motorolamobility/preflighting/checkers/ui/i18n/messages.properties
@@ -0,0 +1,37 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+MissingPermissionsQuickFix_Description=Add required permissions to AndroidManifest.xml
+MissingPermissionsQuickFix_Label=Add required permissions
+
+UnneededPermissionsQuickFix_Description=Remove unneeded permissions from AndroidManifest.xml
+UnneededPermissionsQuickFix_Label=Remove unneeded permissions
+
+DeviceCompatibilityUnsupportedFeaturesQuickFix_Description=Add the android:required="false" attribute to the uses-feature element in AndroidManifest.xml
+QuickFix_CouldNotFixTheProblem=Quick fix could not fix the problem:
+DeviceCompatibilityUnsupportedFeaturesQuickFix_Label=Add android:required="false" to the uses-feature element
+QuickFix_MarkerResolutionFailed=Marker resolution failure.
+
+MissingMinSdkQuickFix_Description=Add android:minSdkVersion to AndroidManifest.xml using the version declared in project.properties
+MissingMinSdkQuickFix_Label=Add missing android:minSdkVersion
+
+UneededMaxSdkQuickFix_Description=Remove the unnecessary android:maxSdkVersion attribute from AndroidManifest.xml
+UneededMaxSdkQuickFix_Label=Remove android:maxSdkVersion from AndroidManifest.xml
+
+ImpliedFeaturesMarkerResolution_Fail_Msg_Dlg_Title=Marker resolution failure.
+ImpliedFeaturesMarkerResolution_Fail_Msg_Manipulate_Manifest=Unable to access the AndroidManifest.xml file.
+ImpliedFeaturesMarkerResolution_Fail_Msg_Save_Manifest=Unable to read AndroidManifest.xml or an error ocurred while trying to save the file.
+ImpliedFeaturesMarkerResolution_Label=Add the implied feature to Androidmanifest.xml \ No newline at end of file