Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Fairphone Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jose Pascoal | 7bf83a0 | 2014-10-13 18:30:18 +0100 | [diff] [blame] | 17 | package com.fairphone.updater.data; |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 18 | |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 19 | import android.content.res.Resources; |
| 20 | import android.text.TextUtils; |
Jose Pascoal | 4091630 | 2015-02-06 18:43:47 +0000 | [diff] [blame] | 21 | import android.util.Log; |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 22 | |
Jose Pascoal | 8a31c8d | 2014-10-17 17:05:29 +0100 | [diff] [blame] | 23 | import com.fairphone.updater.R; |
| 24 | |
Filipe Gonçalves | 4c204d8 | 2015-01-23 15:09:19 +0000 | [diff] [blame] | 25 | import java.util.ArrayList; |
Jose Pascoal | 4091630 | 2015-02-06 18:43:47 +0000 | [diff] [blame] | 26 | import java.util.List; |
Filipe Gonçalves | 4c204d8 | 2015-01-23 15:09:19 +0000 | [diff] [blame] | 27 | |
Tiago Costa | 6d360e2 | 2014-12-15 14:32:51 +0000 | [diff] [blame] | 28 | public class Version extends DownloadableItem implements Comparable<Version> |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 29 | { |
Jose Pascoal | 4091630 | 2015-02-06 18:43:47 +0000 | [diff] [blame] | 30 | private static final String TAG = Version.class.getSimpleName(); |
| 31 | |
| 32 | private static final String DEPENDENCY_SEPARATOR = ","; |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 33 | |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 34 | public static final String IMAGE_TYPE_AOSP = "AOSP"; |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 35 | |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 36 | public static final String IMAGE_TYPE_FAIRPHONE = "FAIRPHONE"; |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 37 | |
Filipe Gonçalves | b31d586 | 2015-02-04 17:28:58 +0000 | [diff] [blame] | 38 | private String mImageType; |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 39 | |
Filipe Gonçalves | b31d586 | 2015-02-04 17:28:58 +0000 | [diff] [blame] | 40 | private String mAndroidVersion; |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 41 | |
Filipe Gonçalves | b31d586 | 2015-02-04 17:28:58 +0000 | [diff] [blame] | 42 | private String mBetaStatus; |
Filipe Gonçalves | 4c204d8 | 2015-01-23 15:09:19 +0000 | [diff] [blame] | 43 | |
Filipe Gonçalves | b31d586 | 2015-02-04 17:28:58 +0000 | [diff] [blame] | 44 | private boolean mErasePartitionsWarning; |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 45 | |
Jose Pascoal | cfc2dd4 | 2015-02-09 18:00:05 +0000 | [diff] [blame] | 46 | private final List<Integer> mDependencies; |
Jose Pascoal | 4091630 | 2015-02-06 18:43:47 +0000 | [diff] [blame] | 47 | |
Maarten Derks | bb28776 | 2015-10-12 17:22:45 +0200 | [diff] [blame^] | 48 | public static final String ZIP_INSTALL_VERSION = "999"; |
Jose Pascoal | 79357c5 | 2015-03-12 20:14:29 +0000 | [diff] [blame] | 49 | |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 50 | public Version() |
| 51 | { |
Jose Pascoal | 4091630 | 2015-02-06 18:43:47 +0000 | [diff] [blame] | 52 | super(); |
Filipe Gonçalves | b31d586 | 2015-02-04 17:28:58 +0000 | [diff] [blame] | 53 | mDependencies = new ArrayList<>(); |
Jose Pascoal | 2666b89 | 2014-10-02 21:05:08 +0100 | [diff] [blame] | 54 | mAndroidVersion = ""; |
Jose Pascoal | 2666b89 | 2014-10-02 21:05:08 +0100 | [diff] [blame] | 55 | mImageType = IMAGE_TYPE_FAIRPHONE; |
Jose Pascoal | cfc2dd4 | 2015-02-09 18:00:05 +0000 | [diff] [blame] | 56 | mErasePartitionsWarning = false; |
Filipe Gonçalves | 4c204d8 | 2015-01-23 15:09:19 +0000 | [diff] [blame] | 57 | mBetaStatus = ""; |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 58 | } |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 59 | |
Jose Pascoal | 060ab28 | 2015-02-09 19:56:08 +0000 | [diff] [blame] | 60 | public Version(Version other) |
| 61 | { |
| 62 | super(other); |
| 63 | mDependencies = other.mDependencies; |
| 64 | mAndroidVersion = other.mAndroidVersion; |
| 65 | mImageType = other.mImageType; |
| 66 | mErasePartitionsWarning = other.hasEraseAllPartitionWarning(); |
| 67 | mBetaStatus = other.mBetaStatus; |
| 68 | } |
| 69 | |
Jose Pascoal | cfc2dd4 | 2015-02-09 18:00:05 +0000 | [diff] [blame] | 70 | public void setEraseAllPartitionWarning() |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 71 | { |
Jose Pascoal | cfc2dd4 | 2015-02-09 18:00:05 +0000 | [diff] [blame] | 72 | mErasePartitionsWarning = true; |
Tiago Costa | 554587b | 2014-06-26 18:39:40 +0100 | [diff] [blame] | 73 | } |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 74 | |
Tiago Costa | 6d360e2 | 2014-12-15 14:32:51 +0000 | [diff] [blame] | 75 | public boolean hasEraseAllPartitionWarning() |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 76 | { |
Tiago Costa | 6d360e2 | 2014-12-15 14:32:51 +0000 | [diff] [blame] | 77 | return mErasePartitionsWarning; |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 78 | } |
Jose Pascoal | 9be8f0d | 2014-03-10 11:22:41 +0000 | [diff] [blame] | 79 | |
Tiago Costa | 6d360e2 | 2014-12-15 14:32:51 +0000 | [diff] [blame] | 80 | public String getAndroidVersion() |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 81 | { |
Tiago Costa | 6d360e2 | 2014-12-15 14:32:51 +0000 | [diff] [blame] | 82 | return mAndroidVersion; |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Tiago Costa | 6d360e2 | 2014-12-15 14:32:51 +0000 | [diff] [blame] | 85 | public void setAndroidVersion(String mAndroid) |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 86 | { |
Tiago Costa | 6d360e2 | 2014-12-15 14:32:51 +0000 | [diff] [blame] | 87 | this.mAndroidVersion = mAndroid; |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 90 | public void setImageType(String imageType) |
| 91 | { |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 92 | mImageType = imageType; |
| 93 | } |
| 94 | |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 95 | public String getImageType() |
| 96 | { |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 97 | return mImageType; |
| 98 | } |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 99 | |
Filipe Gonçalves | 4c204d8 | 2015-01-23 15:09:19 +0000 | [diff] [blame] | 100 | public void setBetaStatus(String betaStatus) |
| 101 | { |
| 102 | mBetaStatus = betaStatus; |
| 103 | } |
| 104 | |
| 105 | public String getBetaStatus() |
| 106 | { |
| 107 | return mBetaStatus; |
| 108 | } |
| 109 | |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 110 | public String getImageTypeDescription(Resources resources) |
| 111 | { |
Jose Pascoal | a860449 | 2014-06-23 19:12:08 +0100 | [diff] [blame] | 112 | return Version.getImageTypeDescription(mImageType, resources); |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 113 | } |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 114 | |
Filipe Gonçalves | b31d586 | 2015-02-04 17:28:58 +0000 | [diff] [blame] | 115 | private static String getImageTypeDescription(String imageType, Resources resources) |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 116 | { |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 117 | String description = resources.getString(R.string.fairphone); |
Jose Pascoal | aa579a8 | 2014-11-05 22:17:16 +0000 | [diff] [blame] | 118 | if (!TextUtils.isEmpty(imageType)) |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 119 | { |
Jose Pascoal | aa579a8 | 2014-11-05 22:17:16 +0000 | [diff] [blame] | 120 | if (imageType.equalsIgnoreCase(IMAGE_TYPE_AOSP)) |
| 121 | { |
| 122 | description = resources.getString(R.string.android); |
| 123 | } |
| 124 | if (imageType.equalsIgnoreCase(IMAGE_TYPE_FAIRPHONE)) |
| 125 | { |
| 126 | description = resources.getString(R.string.fairphone); |
| 127 | } |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 128 | } |
| 129 | return description; |
| 130 | } |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 131 | |
Jose Pascoal | cdd8204 | 2015-02-06 13:04:26 +0000 | [diff] [blame] | 132 | // --Commented out by Inspection START (06/02/2015 12:25): |
| 133 | // public String getAndroidVersion(Resources resources) |
| 134 | // { |
| 135 | // String retVal = ""; |
| 136 | // if (!TextUtils.isEmpty(mAndroidVersion)) |
| 137 | // { |
| 138 | // retVal = resources.getString(R.string.android) + " " + mAndroidVersion; |
| 139 | // } |
| 140 | // return retVal; |
| 141 | // } |
| 142 | // --Commented out by Inspection STOP (06/02/2015 12:25) |
Filipe Gonçalves | b31d586 | 2015-02-04 17:28:58 +0000 | [diff] [blame] | 143 | |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 144 | @Override |
Filipe Gonçalves | b31d586 | 2015-02-04 17:28:58 +0000 | [diff] [blame] | 145 | public int compareTo(@SuppressWarnings("NullableProblems") Version another) |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 146 | { |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 147 | int retVal; |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 148 | if (another != null) |
| 149 | { |
Maarten Derks | bb28776 | 2015-10-12 17:22:45 +0200 | [diff] [blame^] | 150 | if (!this.getNumber().equals(another.getNumber()) && this.mImageType.equalsIgnoreCase(another.mImageType)) |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 151 | { |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 152 | retVal = 1; |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 153 | } |
Jose Pascoal | cfc2dd4 | 2015-02-09 18:00:05 +0000 | [diff] [blame] | 154 | else if (this.getNumber() == another.getNumber() && this.mImageType.equalsIgnoreCase(another.mImageType)) |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 155 | { |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 156 | retVal = 0; |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 157 | } |
| 158 | else |
| 159 | { |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 160 | retVal = -1; |
| 161 | } |
Jose Pascoal | 810950b | 2014-10-09 17:16:08 +0100 | [diff] [blame] | 162 | } |
| 163 | else |
| 164 | { |
Jose Pascoal | 1ee56e2 | 2014-05-21 16:58:20 +0100 | [diff] [blame] | 165 | retVal = 1; |
| 166 | } |
| 167 | return retVal; |
| 168 | } |
Tiago Costa | 6d360e2 | 2014-12-15 14:32:51 +0000 | [diff] [blame] | 169 | |
Jose Pascoal | 4091630 | 2015-02-06 18:43:47 +0000 | [diff] [blame] | 170 | public void setVersionDependencies(String dependencyList) |
| 171 | { |
| 172 | if (TextUtils.isEmpty(dependencyList)) |
| 173 | { |
| 174 | mDependencies.clear(); |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | String[] dependencies = dependencyList.split(DEPENDENCY_SEPARATOR); |
| 179 | for (String dependency : dependencies) |
| 180 | { |
| 181 | try |
| 182 | { |
| 183 | mDependencies.add(Integer.valueOf(dependency)); |
| 184 | } catch (NumberFormatException e) |
| 185 | { |
Jose Pascoal | cfc2dd4 | 2015-02-09 18:00:05 +0000 | [diff] [blame] | 186 | Log.e(TAG, "Invalid dependency: " + e.getLocalizedMessage()); |
Jose Pascoal | 4091630 | 2015-02-06 18:43:47 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Jose Pascoal | 060ab28 | 2015-02-09 19:56:08 +0000 | [diff] [blame] | 192 | // --Commented out by Inspection START (09/02/2015 19:47): |
| 193 | // List<Integer> getVersionDependencies() |
Jose Pascoal | 4091630 | 2015-02-06 18:43:47 +0000 | [diff] [blame] | 194 | // { |
| 195 | // return mDependencies; |
| 196 | // } |
Jose Pascoal | 060ab28 | 2015-02-09 19:56:08 +0000 | [diff] [blame] | 197 | // --Commented out by Inspection STOP (09/02/2015 19:47) |
Kim Hansen | 086964d | 2013-12-10 11:33:28 +0000 | [diff] [blame] | 198 | } |